DataTable order -- when pressing a column header, order the table by another column data

DataTable order -- when pressing a column header, order the table by another column data

zzzzzz Posts: 7Questions: 3Answers: 0

Hi, this is the first time that I'm using a DataTable and I'm trying to do something that I don't know very well if It will be possible or not.

I will try to explain It as much clear as I can.

I have many columns in a DataTable,

What I need: When I press one column header It will change all the table sort.

But when I press that column header I want the table to be ordered by the data from another column.

I mean, If I press the ColumnA header It will be ordered by the ColumnB data, (ColumnBdata1 ColumnBdata2 ColumnBdata3)

Column A |||||| ColumnAdata1 ColumnAdata2 ColumnAdata3 ------------------------------

Column B |||||| ColumnBdata1 ColumnBdata2 ColumnBdata3

I hope It can be done or unless know that It is impossible and not to continue looking for a solution on this way.

Thank you very much in advance, and hope I have explained myself quite correctly.

Answers

  • zzzzzz Posts: 7Questions: 3Answers: 0

    I will response to myself in case that It could be useful for someone else.

    I had a date in the string format : 26/01/2015 and I needed the dataTable order It, but It had no a good result, It just ordered by the day. This is a kind of solution that worked for me.

    My idea is to have two parameters, you need the date as you have now, but a numeric date too, I mean in the case 26/01/2015 convert into a String like 20150126. The DataTable will be able to order It in this format correctly.

    In this case you are ordering the column by a numericDate that can't be seen and you are showing the date as you wanted to see It.

    <td >
    //20150126

    <

    p class="noVisible">${myObject.numericDate}

    <

    p>

    // 26/01/2015
    ${myObject.stringDate}

    </td>

    I hope It could help you, maybe is not a solution but It can help in some cases.

This discussion has been closed.