jqGrid: Disable sorting
Asked Answered
S

2

21

I am adding rows manually to jqGrid using addRowData, and the order of these rows must be maintained.

However, when paging, all rows are reordered to sort by the grid's first visible column.

I have turned off all sorting options that I can find documented.

How can I prevent all sorting and maintain the order of rows across all pages?

Code

Initialization code being used:

$("#grid").jqGrid({
  autowidth: false,
  cmTemplate: {sortable: false},
  colModel: config.gridColumnModel
  height: 600,
  pager: "#aggregationToolbar",
  sortable: false,
  shrinkToFit: false
  url: "fetch",
  viewrecords: false
});

Default settings being used (overridden by the options in the initialization code above):

$.extend($.jgrid.defaults, {
  altClass: "altRow",
  altRows: true,
  autowidth: true,
  cmTemplate: {
    align: "center",
    title: false
  },
  datatype: "local",
  gridview: true,
  height: "auto",
  hidegrid: false,
  jsonReader: {
    page: function(obj) { return 1; },
    records: function(obj) { return obj.length; },
    repeatitems: false,
    root: "objects",
    total: function(obj) { return 1; }
  },
  loadonce: true,
  rowList: [50, 100, 250],
  rowNum: 100,
  sortable: true,
  toppager: true,
  viewrecords: true
});
Stefansson answered 14/11, 2011 at 19:4 Comment(5)
Which value has parameter sortname of jqGrid? Why you need use addRowData? Which datetype you use? It's better if you included the code which you use.Bemean
"sortname" is not being used at all. "addRowData" is used because of some necessary post-processing that is required. The "datatype" is local.Stefansson
In the code example which you posted the datatype is not defined so datatype: 'xml' will be used. Do you use any default settings? Which one? If you use 'local' datatype you can use data parameter of jqGrid which work much more quickly and support of all local features like paging, sorting and filtering. Could you include small demo with the test data which can be used to reproduce your problem?Bemean
Could you include definition of config.gridColumnModel which you use? Could you include test data (at lest two rows)? It can be important to know how which rowid you use. Has the rows id property?Bemean
Could you write more about the "post-processing" which is the main reason of the usage of addRowData and probably event datetype: 'local'. I suspect you try to solve your original problem in a wrong way. Do you load the data from the server and need modify the data received from the server before filling in the grid? In the case there are much more effective way as usage datatype: 'local' and in any way the usage of addRowData in 99% of cases are not needed.Bemean
K
21

For versions that support cmTemplate, you can use:

cmTemplate: { sortable: false }


cmTemplate: Defines a set of properties which override the default values in colModel. For example if you want to make all columns not sortable, then only one propery here can be specified instead of specifying it in all columns in colModel

Kimi answered 20/12, 2012 at 17:12 Comment(0)
U
22

Depending on the jqGrid version you need to make sortable: false on each column specifically + explicitly...

For references see here, here and here.

Until answered 19/11, 2011 at 22:57 Comment(0)
K
21

For versions that support cmTemplate, you can use:

cmTemplate: { sortable: false }


cmTemplate: Defines a set of properties which override the default values in colModel. For example if you want to make all columns not sortable, then only one propery here can be specified instead of specifying it in all columns in colModel

Kimi answered 20/12, 2012 at 17:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.