Combine custom redering with sort from data

Combine custom redering with sort from data

Jens OppermannJens Oppermann Posts: 2Questions: 1Answers: 0

Hello World,

due to too much data I have to switch from HTML to AJAX. Now I am stuck with the following problem.

I have figured out different ways to sort and show.

My data here

{
    "data": [
        {
         sku" : { "sort" : "6003428013000",
        "url" : "ViewProduct-Start?SKU=600342-8013-000&ExtendedNavigation=true"
         "display : "Lorem text"}
        }
    ]
}

I want this with the "sort" value, but i don't know how to receive it from my data.

"columns": [
    {
        "data": "sku",
        "render": function (data) {
            return "<a href='" + data.url + "'>" + data.display + "</a>";
        }
    }
]

This example shows how to reach to the data, but here i can't rendered it properly.

"columns": [
    {
        "data": "sku",
        "render": {
            "_": "display",
            "sort": "sort"
        }
    }
]

Alternative question: or is there a way to create html-data-attributes into the respective cell ?

<td data-dt-filter-attribute="availability" data-sort="2">

Thanks in advance.

Answers

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974

    My understanding it the HTML5 data attributes for data-sort, etc don't work with Ajax loaded data.

    Have you tried using columns.render for the orthogonal data similar to what is shown in the computed example.

    Maybe something like this:

    "columns": [
        {
            "data": "sku",
            "render": function (data, type, row) {
                if (type === "display") {
                  return "<a href='" + row.url + "'>" + row.display + "</a>";
                }
                if (type === "sort") {
                  return row.display
                }
                  return data;
            }
        }
    ]
    

    Note the additional type and row parameters. Also when using something like "data": "sku", you need to use the row parameter to access the other row data.

    Kevin

  • Jens OppermannJens Oppermann Posts: 2Questions: 1Answers: 0

    Thanks mate for your help.

Sign In or Register to comment.