Generate Row Numbering Based on specific Column arrangement
Generate Row Numbering Based on specific Column arrangement
I have a 6 row table with 9 columns.
First column is dedicated for numbering, while 9th column is the default ordering of the table in descending order.
Now i want to number the rows automatically based on 9th column arrangement and also make it searchable and order-able.
Column 9 sample data
39100000000000
6690000000000
3820000000000
2660000000000
1080000000000
540250000000
Taking into account column 9 sample data, whenever the table loads, numbering will be generated in column 1 as seen below.
1
2
3
4
5
6
After table is generated, i also want column 1 sortable and searchable by following the order of column 9.
i.e if column 9 is sorted in ascending order, column 1 would become 6,5,4,3,2,1 and same goes for column 9 too, whenever column 1 is sorted in descending order, column 9 will start from lowest value.
My sample code can be seen here
Any solution would be appreciated.
Replies
Hi @a_j ,
Yep, this was asked before a while ago, and @kthorngren posted this solution on that thread,
Cheers,
Colin
Sounds like you only want to generate the index column once on initialization. I used your example and updated it to use the
init
event.http://live.datatables.net/kuqiwopu/1/edit
Is this what you want?
Kevin
@colin Oh, just seeing that, but don't really know how to apply it to my code, or how to change my code to fit.
@kthorngren Yes, that is what i need, but your solution doesn't seem to make column 1 sortable or searchable. Any advice?
The example doesn't use Datatables API's to update the column - the HTML is directly updated. I added
rows().invalidate()
to have Datatables refresh its cache after updating the column. Plus a commented out{targets: 0, searchable: false, orderable: false},
.http://live.datatables.net/kuqiwopu/3/edit
Kevin
@kthorngren Issue is now resolved.
Thanks alot, really appreciate.