Column Order Direction Always "asc" when ordering by second column - Server Side Rendering

Column Order Direction Always "asc" when ordering by second column - Server Side Rendering

densel34densel34 Posts: 3Questions: 0Answers: 0
edited February 2022 in Free community support

Hey, I am using Datatables 1.10.21 and Datatables RowsGroup v1.0.0 with Server-side rendering.

FRONTEND: I am calling server-side URL with AJAX like this...

table= $(table).DataTable({
        "processing": true,
        "serverSide": true,
        "aaSorting": [[0, "desc"]],
        //"order": [[0, "desc"]],
        "ajax": {
            "url": config.procurements.getProcurementsURL,
            "type": "POST",
            "datatype": "json",
            "orderMulti": false,
            "searchable": true,
            "orderable": true,
            "sortable": true,
            "lengthChange": true,
            "scrollCollapse": false,
            "data": function (d) {
                d.CustomFilter = $('#Filter_CustomFilter').val();
                d.FinalControlFilter = document.getElementById('Filter_FinalControlFilterBool').checked == false ? 0 : 1;
                d.ProdAlumColorFilter = $('#Filter_ProdAlumColorFilter').val();
            },
        },
        "rowsGroup": [
            0,
            1,
            2,
            12
        ],
    });

    new $.fn.dataTable.FixedHeader(table);
}

BACKEND: And my SERVER SIDE method is...

public ActionResult GenerateProcurements(){
                int startRec = Convert.ToInt32(Request.Form.GetValues("start")[0]);
                int pageSize = Convert.ToInt32(Request.Form.GetValues("length")[0]);
                int customFilterType = Convert.ToInt32(Request.Form.GetValues("CustomFilter")[0]);
                int alumColorFilter = Convert.ToInt32(Request.Form.GetValues("ProdAlumColorFilter")[0]);
                int finalControlFilter = Convert.ToInt32(Request.Form.GetValues("FinalControlFilter")[0]);
                string search = Request.Form.GetValues("search[value]")[0];
                string draw = Request.Form.GetValues("draw")[0];

                string order = Request.Form.GetValues("order[0][column]")[0];
                string orderDir = Request.Form.GetValues("order[0][dir]")[0];
}

If I select Column 0 order I get the correct values for 'order' and 'orderDir'. When I Select Column 1 order it shows server side code collect the correct 'order' value (e.g. "1"), but 'order' is always equal to "asc".

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Replies

  • allanallan Posts: 61,832Questions: 1Answers: 10,133 Site admin

    I'm not seeing that happen in this example I'm afraid. Can you give me a link to a test case showing the issue please.

    Thanks,
    Allan

  • densel34densel34 Posts: 3Questions: 0Answers: 0

    I am using Row Grouping plugin and I think that is a problem. If I use server-side processing without row grouping it works fine.

  • kthorngrenkthorngren Posts: 20,371Questions: 26Answers: 4,779

    Two things:

    1. You are using a plugin called RowsGroup which is developed by a third party. I believe this is the githib repo. For problems with this plugin you will need to ask for help from the plugin's developer. An alternative is to use the Datatables RowGroup extension.
    2. Lines 10-15 of the above code snippet are inside the ajax option. They need to be moved outside at the same level as lines 2-4. Also searchable, orderable and sortable aren't valid options. They are options applied to columns. See the columns.orderable and columns.searchable for more details.

    Kevin

  • kthorngrenkthorngren Posts: 20,371Questions: 26Answers: 4,779

    IIRC the rowsGroup plugin forces the column oder to asc in order to build the groups. You can confirm this with the developer or by looking at the code.

    Kevin

  • densel34densel34 Posts: 3Questions: 0Answers: 0

    I realized that double-click on the column sort option (when "ASC" is active) send order="DESC" on the server-side.

    I will try to contact the plugin author for additional info.

    Thank you so much.

Sign In or Register to comment.