0

I have a PHP-script to handle the AJAX-Requests of many different jqGrid's.

I generate the "ORDER BY" statement with the 'sidx' and 'sord' parameters and the "LIMIT" statement with the 'page' and 'rows' parameters.

Similar to the PHP-example here.

The problem is, that in the PHP-script I can not determine if the loadonce-parameter of the current jqGrid is set or not. But only if it is not set, I have to filter the returned data (LIMIT by page and rows).

How can I force jqGrid to send an additional parameter? I dont want to change all my Grids. Is there a global way of doing it?

------ EDIT ------

With the help from this answers (here and here) i got this now.

$.extend($.jgrid.defaults, {
    postData: {
        loadingType: function() {
            var isLoadonce = $("#list1").jqGrid('getGridParam', 'loadonce');
            console.log('isLoadonce: ' + isLoadonce);
            return isLoadonce ? 'loadAll' : 'loadChunk';
        },
    },
});

This works, if the Grid has the ID "list1". How can I reference the current Grid without ID?

------ EDIT 2 ------

This seems to work. It looks to me a bit like a hack. Is there a better way?

$.extend($.jgrid.defaults, {
    serializeGridData: function(postData) {
        var isLoadonce = $(this).jqGrid('getGridParam', 'loadonce');
        var newPostData = $.extend(postData, {
            loadingType: isLoadonce ? 'loadAll' : 'loadChunk'
        });
        return $.param(newPostData);
    },
});
Community
  • 1
  • 1
Stahlkocher
  • 219
  • 4
  • 10
  • could you please provide a jsfiddle with the problem? – radu florescu Jan 25 '13 at 11:46
  • @Floradu88 I dont know what i could show you in a jsFiddle. My Problem is not that a Grid is not working. But I want to know if there is a way to extend the ajax-request of a Grid. – Stahlkocher Jan 25 '13 at 12:16

2 Answers2

2

To pass in an extra parameter you can add:

 postData: { ExtraDataName: ExtraDataValue },

then whenever jqGrid goes to get data it will pass that name pair to your controller.

Mark
  • 3,123
  • 4
  • 20
  • 31
  • Yes, but this way the additional value is static. On the server site I want to know if the current grid is "loadonce". With my second "EDIT" I found a way to archive this. I just dont know if this is the best way of doing it. – Stahlkocher Jan 28 '13 at 10:32
  • I'm not sure I understand the problem? In my example above if you want to pass in the loadonce value you would just set `ExtraDataName: $(this).jqGrid('getGridParam', 'loadonce');` – Mark Jan 28 '13 at 12:18
0

With serializeGridData, jqGrid provides an event to modify the data sent with the Request. The event is called in the context of the current Grid, so we can access the current Grid with this.

By exdending $.jgrid.defaults we can make all Grids sending their loadonce parameter as additional requestparameter without changing any Grid.

$.extend($.jgrid.defaults, {
    serializeGridData: function(postData) {
        var isLoadonce = $(this).jqGrid('getGridParam', 'loadonce');
        var newPostData = $.extend(postData, {
            loadingType: isLoadonce ? 'loadAll' : 'loadChunk'
        });
        return $.param(newPostData);
    },
});
Stahlkocher
  • 219
  • 4
  • 10