Add row numbers
Add row numbers
csaba911
Posts: 17Questions: 4Answers: 0
Added row numbers with JavaScript to html but its not sortable as server side processing enabled.
Any tips on how to add row numbers to django json without altering table structure or models ?
Example would nice as im not a level "expert" in python or django.
Thanks
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
As you've got
server-side
enabled, searching needs to be done on the server, so the row numbers would need to come from there too.Colin
Agree, you suggesting this should be a Django forum question than ?!
The simple answer is to loop through the data retrieved from the DB table and add the index before sending the JSON response. This would result in all pages using the same row numbers, for example, page 1 will have the same. row numbers as page 2.
If this isn't what you want then you will need to determine how to dynamically keep track of the row numbers. Providing specifics of how to do this would take knowledge of your Python environment and solution requirements.
If you have specific Python or Django questions it would be better to use a forum geared towards those questions. There are sone third party Django libraries that handle server side processing for Datatables. If you are using one of those that might be a good place to ask.
Kevin
Done that exactly what you suggested, and no, not the result I was looking for as count will reset on every page and only can sort the displayed 10 rows.
The reason I was hopping to find answer here because the datable know exactly there is 388 result, displaying 10 (or this was sent whit this info by json processing ?)
I think I know what is need to be done just don't know how to
Datatables knows this from the response. The doc explains the protocol.
The biggest problem I see is making sure a particular row keeps the same index when the table is sorted or searched. I guess this will depend on the requirements.
Kevin