AJAX Server side sorting when using paging

AJAX Server side sorting when using paging

xnetdudexnetdude Posts: 6Questions: 2Answers: 0
edited April 2020 in Free community support

We use server side paging/sorting/filtering in c# / asp.net core and have an issue with rendered columns. For example, we have the following column made up from a class returned within the ajax call :

                {
                    "data": "Person",
                    render: {
                        _: "FirstName",
                        sort: "FirstNameSort"
                    }
                },

When the column heading is selected to change the sort order, the POSTed back info with the client/server side properties shows DTParameters.SortOrder = "Person" and not "FirstNameSort". This is obviously because that's the object's name but I would have "expected" this to have returned "FirstNameSort" as this is the sort column.

I appreciate that sort column convention works well on client side sorting, but how do you get "FirstNameSort" back to the server side without creating a condition for each column and checking the "type" of the column?

Thanks.

James.

This question has an accepted answers - jump to answer

Answers

  • xnetdudexnetdude Posts: 6Questions: 2Answers: 0

    Potentially answering my own question but hope it helps someone else (unless there is a better way).

    We can use the "name" property to specify the sort column like this:

    {
        "data": "Person",
        render: {
            _: "FirstName",
            sort: "FirstNameSort"
        },
        "name":"FirstNameSort"
    },
    

    This name gets returned in the DTParameters object "Columns" property. We can then correlate the sort order column number with this column and use the "name" property(ies) for the dynamic order by clause.

    Let me know if there is a "more correct" way.

    Thanks again.

  • colincolin Posts: 15,166Questions: 1Answers: 2,588
    Answer ✓

    Yep, that's a good way to go,

    Colin

  • xnetdudexnetdude Posts: 6Questions: 2Answers: 0

    Thank you as always Colin for your continued great work on this. Stay well.

This discussion has been closed.