sort a specific color of a column out.

sort a specific color of a column out.

ak1984ak1984 Posts: 4Questions: 1Answers: 0

Hallo together, I really don´t know what to do.

I have this table, i want to click on a head of column (in blue), you can see there are green and red in the body. i want all the rows with red background on this column order come all up(reorder , order upwards.) Is it really possible, and what should i do?
thanks very much!!!

This question has accepted answers - jump to:

Answers

  • colincolin Posts: 13,279Questions: 0Answers: 2,268
    Answer ✓

    columns.render can return a value for sort that would group the colours togethers - for example the function could just return red, green and blank, meaning they would remain in that grouping.

    Colin

  • ak1984ak1984 Posts: 4Questions: 1Answers: 0

    thanks Colin, thanks for your answer, do i need extra APIs? not so familiar with 'render'. Does it support sort of other columns. I mean i sort One column,i saw the result. and then i want to sort another column, I click on the head, this column will do exactly the same as the previous one, based on the 'old ' data?

  • colincolin Posts: 13,279Questions: 0Answers: 2,268
    Answer ✓

    This example should help - it's doing something similar with the Rarity column. You can see how the return value affects the ordering,

    Colin

  • ak1984ak1984 Posts: 4Questions: 1Answers: 0

    Hallo Colin, i try to use the html5 attributes, data-sort. because my data is not from ajax , when i do this , populatedly generating my td, and generating data-sort attribute in javascript. but datatable is still not sorting, as if it doesn´t know the data-sort attribute exists. I do follow :

    https://datatables.net/examples/advanced_init/html5-data-attributes.html

    $(mydocument).ready(function() {
    $('#example').DataTable();
    } );

  • kthorngrenkthorngren Posts: 14,616Questions: 25Answers: 3,469

    Can you build a simple test case showing what you are doing?

    My understanding is that the DOM sourced table needs to have HTML data attribute (data-sort) when Datatables initializes for that attribute to be used for orthogonal data. If they aren't there at initialization then Datatables won't try using them later.

    Kevin

  • ak1984ak1984 Posts: 4Questions: 1Answers: 0

    Hi Kevin, this is a simple example:

    var tr=document.createElement("tr");
    var td=document.createElement("td");
    td.innerHTML="sth";
    if(ok){
    td.setAttribute("data-order","red");
    td.style.background="#ff7d7d";
    }
    .......

    $("#mainTable").DataTable({})

  • kthorngrenkthorngren Posts: 14,616Questions: 25Answers: 3,469

    Please provide a running test case so we can see how the code is working.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • kthorngrenkthorngren Posts: 14,616Questions: 25Answers: 3,469

    Maybe this thread will help.

    Kevin

Sign In or Register to comment.