Easygrid icon indicating copy to clipboard operation
Easygrid copied to clipboard

addFunction executes on page load?

Open jimdodson opened this issue 10 years ago • 4 comments

Grails 2.4.3 EasyGrid 1.6.8

I would like to use addFunction to display a create form in a div.

However, when I load the page, the addFunction seems to be called automatically - the grid is displayed then the create form appears. Have I missed something?

gsp:

  <g:set var="addFunc" value="${g.remoteFunction(action: 'create', update: 'entryDiv')}"/>
  <grid:grid name="entry" addFunction="${addFunc.replaceAll(';','')}">
   <grid:set caption="Category" width="1100" />
   <grid:set col="id" formatter="f:customShowFormat" />
   <grid:set col="BEGIN_DTE" searchoptions.dataInit="f:dateRender"/>
   <grid:set col="END_DTE" searchoptions.dataInit="f:dateRender"/>
  </grid:grid>
  <div id="entryDiv"></div>

jimdodson avatar Nov 13 '14 17:11 jimdodson

Can you do a "view source" and copy-paste the resulted javascript code here?

tudor-malene avatar Nov 13 '14 22:11 tudor-malene

<script type="text/javascript">jQuery(function(){
    jQuery("#entry_table").jqGrid({
    url: '/tmui/category/entryRows',
    loadError: easygrid.loadError,
    pager: '#entryPager',
    "inlineEdit":false,"viewrecords":true,"height":240,"rowList":[10,20,50],"width":"1100","caption":"Category","datatype":"json","multiSort":true,"rowNum":10,



        editurl: '/tmui/category/entryInlineEdit',
        cellurl: '/tmui/category/entryInlineEdit',
        <!--  onSelectRow: easygrid.onSelectRowInlineEdit('entry_table'),  -->

    colModel: [


            {"formatter":customShowFormat,"searchoptions":{"clearSearch":false},"search":false,"hidden":false,"name":"id","width":25,"resizable":false,"label":" ","editable":false

            },



            {"searchoptions":{"clearSearch":false,"sopt":["cn","nc","eq","ne","bw","ew"]},"editable":true,"name":"CLASS_CDE","search":true,"label":"Class Code"

            },



            {"searchoptions":{"clearSearch":false,"sopt":["cn","nc","eq","ne","bw","ew"]},"editable":true,"name":"CATG_NME","search":true,"label":"Category Name"

            },



            {"searchoptions":{"clearSearch":false,"sopt":["eq","ne","lt","le","gt","ge"]},"editable":true,"name":"CATG_CDE","search":true,"label":"Category Code"

            },



            {"searchoptions":{"clearSearch":false,"sopt":["eq","ne","lt","le","gt","ge"],"dataInit":dateRender},"editable":true,"name":"BEGIN_DTE","search":true,"label":"Effective Begin"

            },



            {"searchoptions":{"clearSearch":false,"sopt":["eq","ne","lt","le","gt","ge"],"dataInit":dateRender},"editable":true,"name":"END_DTE","search":true,"label":"Effective End"

            },



            {"searchoptions":{"clearSearch":false,"sopt":["eq","ne","lt","le","gt","ge"]},"editable":true,"name":"RULESET_ID","search":true,"label":"Ruleset"

            },



            {"searchoptions":{"clearSearch":false,"sopt":["eq","ne","lt","le","gt","ge"]},"editable":true,"name":"SOURCE_CDE","search":true,"label":"Source Code"

            },



            {"searchoptions":{"clearSearch":false,"sopt":["cn","nc","eq","ne","bw","ew"]},"editable":true,"name":"REQUEST_ID","search":true,"label":"Request"

            },



            {"searchoptions":{"clearSearch":false,"sopt":["cn","nc","eq","ne","bw","ew"]},"editable":true,"name":"COMMENTS_TXT","search":true,"label":"Comments"

            },



            {"label":"Approval Status","searchoptions":{"clearSearch":false,"sopt":["cn","nc","eq","ne","bw","ew"]},"search":true,"hidden":true,"editable":true,"name":"STATUS_IND"

            },



            {"label":"category.OPERATOR_ID.label","searchoptions":{"clearSearch":false,"sopt":["cn","nc","eq","ne","bw","ew"]},"search":true,"hidden":true,"editable":true,"name":"OPERATOR_ID"

            },


    ],

        afterInsertRow: function(rowid,rowdata,rowelem) {
            if (rowdata.STATUS_IND == 'N') {
                if (rowdata.OPERATOR_ID != null) {
                    $('tr#' + rowid).find("td").css('background-color', 'rgb(231,231,31)');
                }
            }
            if (rowdata.STATUS_IND == 'R') {
                $('tr#' + rowid).find("td").css('background-color', 'rgb(231,31,31)');
            }
        }   // render properties defined in the gsp

    });


        jQuery('#entry_table').jqGrid('filterToolbar', {"stringResult":true,"searchOperators":true});



        jQuery('#entry_table').jqGrid('navGrid','#entryPager',
        {"search":false,"edit":false,"del":false,"view":false,"add":false,"refresh":true},
        {},     //edit
        {"afterSubmit":easygrid.afterSubmit('entry_table'),"errorTextFormat":easygrid.errorTextFormat('entry_table'),"reloadAfterSubmit":false,"closeAfterAdd":true},     //add
        {},     //delete
        {"multipleSearch":true,"multipleGroup":true,"showQuery":true,"caption":"Multi-clause Searching","closeAfterSearch":true,"sopt":["eq","ne","lt","le","gt","ge","bw","bn","ew","en","cn","nc","nu","nn"]},     //search
        {"closeOnEscape":true}     //view
        )


            .jqGrid('navButtonAdd','#entryPager',{caption:"", buttonicon:"ui-icon-plus", onClickButton:jQuery.ajax({type:'POST', url:'/tmui/category/create',success:function(data,textStatus){jQuery('#entryDiv').html(data)},error:function(XMLHttpRequest,textStatus,errorThrown){}})});


}); </script>

jimdodson avatar Nov 14 '14 13:11 jimdodson

Try to wrap the addFunc code in a function (){}:

  <grid:grid name="entry" addFunction="function(){${addFunc.replaceAll(';','')}}">
..

tudor-malene avatar Nov 15 '14 10:11 tudor-malene

Thank you Tudor - it works perfectly.

On Sat, Nov 15, 2014 at 4:08 AM, Tudor Malene [email protected] wrote:

Try to wrap the addFunc code in a function (){}:

<grid:grid name="entry" addFunction="function(){${addFunc.replaceAll(';','')}}"> ..

— Reply to this email directly or view it on GitHub https://github.com/tudor-malene/Easygrid/issues/126#issuecomment-63167128 .

jimdodson avatar Nov 17 '14 16:11 jimdodson