Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
577 views
in Technique[技术] by (71.8m points)

jquery - jqGrid sorting a column while grouping consider grouping header

I have jqgrid. I've grouped few rows based on a column value. Working demo is available at 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);
        }
    });

Following is how my grid looks like jqGrid after grouping

Issue: Is it possible to sort rows in this grid so that the final grid has rows in the following Order

  • Alabama
  • D
  • Maine
  • NewJersey
  • Q
  • Virginia
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If I correctly understand your problem you can solve your problem by adding custom sorting function (see here, here and here) on the column DocGroup where you do the grouping:

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

As the result the input data which have empty DocGroup will be sorted and so grouped by Documents. You will see the results on Fiddle

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...