0

I will have many jqGrid tables at my application. However it is not easy to write every configuration of it again and again

(i.e.

viewrecords: true,
sortorder: "desc",
multiselect: true,
multiboxonly: true,

)

How can I instruct a basic grid and extend and overwrite its configurations from other grids to have less code?

kamaci
  • 72,915
  • 69
  • 228
  • 366

3 Answers3

0

See the documentation at http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options

Create the options array once and pass it in when you create the other grids. To set the defaults for all grids, see the bottom of the docs called "Setting Options Globally" which may be what you want.

jcadcell
  • 791
  • 1
  • 8
  • 19
0

Just make a jqgrid adapter and use it instead of jqgrid.

jQuery.fn.jqGridAdapter = function(options) {
    options = jQuery.extend(options, {viewrecords: true,
        sortorder: "desc",
        multiselect: true,
        multiboxonly: true,
    });
    jQuery(this).jqGrid(options);
}
$('#table').jqGridAdapter();

With such adapter in case of new version of jqgrid that require changes in your code, you will have to change only this function.

Ivan
  • 2,262
  • 1
  • 18
  • 16
0

You can use the following before creating any jqGrid.

$.extend($.jgrid.defaults, {
    viewrecords: true,
    sortorder: "desc",
    multiselect: true,
    multiboxonly: true
});

Moreover I recommend you to use column templates. See here and here for more information.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798