Add row numbers

Add row numbers

csaba911csaba911 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

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    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

  • csaba911csaba911 Posts: 17Questions: 4Answers: 0

    Agree, you suggesting this should be a Django forum question than ?!

  • kthorngrenkthorngren Posts: 21,174Questions: 26Answers: 4,923
    Answer ✓

    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

  • csaba911csaba911 Posts: 17Questions: 4Answers: 0

    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 ?)

  • csaba911csaba911 Posts: 17Questions: 4Answers: 0

    I think I know what is need to be done just don't know how to :/

  • kthorngrenkthorngren Posts: 21,174Questions: 26Answers: 4,923

    because the datable know exactly there is 388 result, displaying 10 (or this was sent whit this info by json processing ?)

    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

This discussion has been closed.