when column has two values how to support sorting indepdently for those two
when column has two values how to support sorting indepdently for those two
umaeswara
Posts: 83Questions: 16Answers: 0
in this example https://datatables.net/examples/advanced_init/column_render.html
the first column has both name and age ; can we support sorting with name and also sorting with (age) ?
can you please help how can we do that in a single column? i don't want to separate the columns.
i want to keep both name and age in a single column, but have a provision to sort them too.
This discussion has been closed.
Answers
BTW, i was trying to recreate the example but it shows Name (undefined). please help there too. my example is : http://live.datatables.net/xizuhilu/1/edit
i have used Name and row[3] (Extn values) for creating my first column. it shows up as Name (undefined).
my example link : http://live.datatables.net/vovewaza/1/edit
previous link got overwritten for some reason.
Your example is using objects not arrays so you need to access the row data using object notation. Instead of
row[3]
userow.extn
. Updated example:http://live.datatables.net/vovewaza/2/edit
I added an additional Ashton Cox row with a different extension. When sorting by name the extension is part of the string so the extn is effectively sorted. Is this what you are looking for? If not please provide more details of how you wold like this to work.
Kevin
thanks Kevin for the reply. it resolved my including extension correctly. thank you.
Coming to the sorting i would like to have two sorting icons ( or something like that available ) for my first column. such that when I click on Name sorting, it sorts by name. when I click (age) it sorts by Age number only. But they both should be in one column. i dont want to seperate them in two columns to have the sorting feature work.
for example:
Name (Age)
Aname (12)
Bname (6)
Cname (14)
When i click on Name:
Aname (12)
Bname (6)
Cname (14)
When I click on (Age):
Bname (6)
Aname(12)
Cname (14)
thanks,
Uma-
You can use the
order()
API on the hidden column, assuming you have a button or some other input to sort by Age. See this example:http://live.datatables.net/vovewaza/3/edit
Kevin
Thanks Kevin, This is fantastic. i will see if I can add that button inside my column. Thank you for quick reply.