Read HTML to data and preserve data-sort attribute.

Read HTML to data and preserve data-sort attribute.

JeffSinclairJeffSinclair Posts: 1Questions: 0Answers: 0

Currently I use the data-sort attribute successfully in places.
In other cases we read into an object,
based on this example : https://datatables.net/examples/advanced_init/object_dom_read.html

However I have been unable to get the data-sort attibute to work once the colomn data object is used.

Replies

  • allanallan Posts: 63,451Questions: 1Answers: 10,465 Site admin

    It is a bit awkward, and perhaps the documentation on it isn't quite right, but it is possible:

    var table = new DataTable('#example', {
        columns: [
            { data: 'name' },
            { data: 'position' },
            { data: 'office' },
            { data: 'age' },
            { data: 'start_date' },
            {
              data: {
                _: 'salary.display',
                type: 'salary.@data-sort',
                sort: 'salary.@data-sort',
              }
            }
        ]
    });
    

    Example: https://live.datatables.net/wobicaro/1/edit

    Allan

Sign In or Register to comment.