JqGrid column sorting when grouping considers header grouping

I have jqgrid. I have grouped several rows based on the column value. A working demo is available at the link part of the code that defines jqGrid

    var preclosingtable = $('#preclosing');
    preclosingtable.jqGrid({
        datatype: 'local',
        data: data.DOCS,
        colNames: ['', 'Documents Received', 'Comments', 'NA', 'DocGroup'],
        colModel: [
        { name: 'Documents', index: 'Documents', align: 'left', sortable: false, editable: false, width: 20 },
        { name: 'DocsReceived', index: 'DocsReceived', align: 'center', sortable: false, editable: true, edittype: 'checkbox', editoptions: { value: "True:False" }, formatter: "checkbox", width: 140 },
        { name: 'Comments', index: 'Comments', align: 'center', sortable: false, editable: true, edittype: "textarea", editoptions: { rows: "3", cols: "16" }, width: 180 },
        { name: 'NA', index: 'NA', editable: true, formatter: 'dynamicText', width: 150, edittype: 'custom', editoptions: { custom_element: radioelem, custom_value: radiovalue} },
            { name: 'DocGroup', index: 'DocGroup', editable: false, width: 1 }
        ],
        rowNum: data.DOCS.length,
        //rowList: [10, 20, 30],
        pager: '#preclosingpagerdiv',
        viewrecords: true,
        sortorder: "asc",
        sortname: 'Documents',
        grouping: true,
        groupingView: {
            groupField: ['DocGroup'],
            groupColumnShow: [false],
            groupDataSorted: true,
            groupOrder : 'asc'
        },
        localReader: {
            id: 'ConfigId'
        },
        shrinkToFit: false,
        height: 'auto',
        loadComplete: function () {
            HideGroupHeaders(this);
        },
        onSelectRow: function (id) {
            preclosingtable.jqGrid('saveRow', previouslyselectedRow, false, 'clientArray');
            previouslyselectedRow = SetJQGridRowEdit(id, previouslyselectedRow, preclosingtable);
        }
    });

This is what my grid looks like jqGrid after grouping

Problem. Is it possible to sort the rows in this grid so that the final grid has rows in the following order

  • Alabama
  • D
  • Maine
  • Newjersey
  • Q
  • Virginia
+5
source share
2 answers

If I understand your problem correctly, you can solve your problem by adding a custom sort function (see here , here and here ) in the column DocGroupwhere you group:

sorttype: function (cellvalue, rowObject) {
    return cellvalue? cellvalue : rowObject.Documents;
}

, DocGroup, Documents. Fiddle

enter image description here

+10

, . - , beforeProcessing jqGrid.

beforeProcessing , , ( D, Q ), .

beforeProcessing, , :

        beforeProcessing: function (data, status, xhr) {
            for (var x = 0, length = data.rows.length; x < length; x++) {
                var valueToPutInSortColumn = ....
                data.rows[x].cell.splice(sortColumnIndex, 0, valueToPutInSortColumn );
            }
        ....
+1

All Articles