简体   繁体   中英

How can I have a sortable column based on a nested object of data.record?

I'm using jquery jtable to display some data to a table. For each field in the table, I use something along the lines of this to display the data and support sorting:

sorting: true,
display: (data) =>{
    return data.record.<whatever_value>;
}

And this works for every field I have in the table, except for one in which I need to sort based on a nested object within record. But it doesn't work it I do this instead:

sorting: true,
display: (data) =>{
    return data.record.<Nested_Object>.<Nested_value>;
}

I cannot for the life of me figure out what the issue is. If anybody can point me in the right direction, I'd really appreciate it. Cheers.

jTable does not do any sorting. All the sorting is actually done on the server. Jtable sends a listAction request with the parameter jtSorting = "fieldName ASC/DESC";

On the server usually all that is performed is to validate the parameter and pass it to the database in the ORDER clause. In your case you will need to recognise the special field and provide a compound ORDER clause for any number of subfields you need to sort by.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM