1

I've noticed that multi grouping in JQGrid elicits rows sorting to be rearranged inline once the list of values is retrieved through ajax getJSon(). Sometimes the reordering splits groups of the same elements in more than one group, as it should be.

I guess the solution is to avoid client side re-sorting of JQGrid rows, with the aim to definitively reuse the same order given inside the JSON without changes --- as returned by the server.

I'm using the following configuration :

jq("#myGrid").jqGrid({
  datatype: 'local',
  data: myvar.detail,  // a well formatted json locally stored
  colNames: [ ....],
  colModel: [
    {name:'nome_attr',index:'nome_attr', sorttype: function () {return 1;}, editable:true, editrules:{required:true}, editoptions:{size:27}, align:'center'},
    {name:'desc_attr', index:'desc_attr', sorttype: function () {return 1;}, editable:true, editrules:{required:false}, edittype: "textarea",editoptions:{rows:5, cols:25}, hidden:true},
    {name:'valore',index:'valore', sorttype: function () {return 1;},editable:true, editrules:{required:false}, editoptions:{size:30}, width:120},
     ....
          ],
   loadonce: false,     // to dis-able sorting on client side
   sortable: false,     
   grouping:true,
   groupingView : {
         groupField : ['nome_attr', 'valore'],
         groupColumnShow: [false,false],
         groupText : ['{0}'],
         groupCollapse: true,
         groupDataSorted: false, 
         groupSorted: false, 
         groupOrder: false
        }
  });

Notice (1) I'm already using the workaround to disable the sort type

 sorttype: function () {return 1;}

as described here, and that in "#myGrid" is a sub-grid, where the datatype: local, means the rows have been previously retrieved in the container grid.

Does anybody knows which is the configuration of the colModel attribute and the groupingView parameters to be set in order to avoid in-line re-sorting in case of Multi Grouping ?

thanks in advance,

Michele

Community
  • 1
  • 1
m.piunti
  • 340
  • 2
  • 8

1 Answers1

0

One workaround to fix the automatic sort is to allow the client to work in order to re-produce the same list of values (recreating the same order).

First, prepare a JScript function forcing the right order value for each grouped column:

   /** 
    * Sort type in subgrid's gropued rows
    */
   function sortGroup(cellValus, rowData, ty) {     
       if(ty==='attribute_1')
        return rowData.attr1_order;
       else if(ty==='attribute_2')
        return rowData.attr2_order;
    }

Second, inject the desired order values in the colModel.

Third, trigger the previous function inside the sorttype in each grouped column, using the column type to know which group the order belongs:

  colModel: [
     {name:'nome_attr',index:'nome_attr', sorttype: function (cellValus, rowData) {return sortGroup(cellValus, rowData, 'attribute_1')}, editable:true, editrules:{required:true}, editoptions:{size:27}, align:'center'},
     {name:'desc_attr', index:'desc_attr', editable:true, editrules:{required:false}, edittype: "textarea",editoptions:{rows:5, cols:25}, hidden:true},
     {name:'valore',index:'valore', sorttype: function (cellValus, rowData) {return sortGroup(cellValus, rowData, 'attribute_2')},editable:true, editrules:{required:false}, editoptions:{size:30}, width:120},
      .....
     {name:'attr1_order',index:'attr1_order', editable:false, hidden:true},
     {name:'attr2_order',index:'attr2_order', editable:false, hidden:true}
     ]
m.piunti
  • 340
  • 2
  • 8