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');
        },
jayAnn
  • 827
  • 3
  • 18
  • 38

1 Answers1

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*/});
Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798