0

hey, good day. im creating a program that would load a data from a server into a jqgrid. what im trying to do now is create a function from a separate javascript file and just use that function in my other javascript-jqgrid-load-data. here's my code in javascript:

    $("#tbl").jqGrid({
        url: '',                            
        datatype: 'local',      
        jsonReader : {              
            root: function(obj) {
            //some codes here

               return root;
            },          
            page: "page",                   
            total: "pageCount",     
            records: "rows",    
            repeatitems:false,  
            id: "0" 
        },

        serializeGridData: function(postData) {
            var jsonParams = {
                .
                .//some codes here
                .

                'sort_fields': postData.sidx
            };

            if (postData.sord == 'desc')
            {
            ..//some codes
            }           
            else
            {
            ...//some codes
            }

            jpar = jsonParams;
            return 'json=' + jsonParams;
        },

        loadError: function(xhr, msg, e) { 
            showMessage('msg error');
        },
        colNames:['ID',...'Type'],      
        colModel:[
        ...//col model
        ],

        rowNum:5,           
        .
        .
        .//some codes here
        loadonce:false,         
        caption: "Main Account Group"
    });

i want to separate the code:

         jsonReader : {             
            root: function(obj) {
            //some codes here

               return root;
            },  
            page: "page",                   
            total: "pageCount",     
            records: "rows",    
            repeatitems:false,  
            id: "0" 
         },

and this:

         serializeGridData: function(postData) {
            var jsonParams = {
                .
                .//some codes here
                .

                'sort_fields': postData.sidx
            };

            if (postData.sord == 'desc')
            {
            ..//some codes
            }           
            else
            {
            ...//some codes
            }

            jpar = jsonParams;
            return 'json=' + jsonParams;
        },
        loadError: function(xhr, msg, e) { 
            showMessage('msg error');
        },

1 Answer 1

1

I wrote my answer your your next question so that it answer on both from your question. The main idea is that you can either use global functions or better redefine jqGrid defaults with respect of

jQuery.extend(jQuery.jgrid.defaults, {/*your changes to the defaults*/});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.