Index column and deferRender
Index column and deferRender

Question originally raised by : AxelaAxela
January 2017in Free community support , I came accross the same problem :
I have a table where I would like to add a column where the user could see row indexes, like in this example. The problem is that the table has quite a bit of rows and expected to be accessed from mobile so, as one would expect, I'd like to have it loading as fast as it's possible. One of ways to make it faster is to use deferRender option which really improves loading speed but it's not compatible with the code for index column because it generates IDs only for first page.
So, I was wondering if there is some other mechanism to add that column while keeping deferRender on.
This question has an accepted answers - jump to answer
Answers
Maybe you can generate the indexes in your server script?
Kevin
Here is how I generated the indexes in my script
"fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
//debugger;
var index = iDisplayIndexFull + 1;
$("td:first", nRow).html(index);
return nRow;
},
Generating indexes as above reflects in print export but the same doesn't in Excel file. Please help
The problem with that solution is it doesn't update the Datatables data cache. Which is why the exports don't have the indexes. You could change this example to itereate all the rows and update the data. Something like this example:
http://live.datatables.net/vewenani/1/edit
If you are using
deferRender
then my example may not be what you want. It may take too long. Thats why I suggested that your server script should add the index. You may be able to add an index column to your DB query.Kevin
Since, my database is over 5K records each of more than 40 columns, I am using deferRender for seamless loading and resultantly unable to export index colum to excel and my clients insist for the same. Please guide..
Did you look at the example I provided in my last post? Did you try it?
Not sure what your data source is but here is a thread that discusses adding an index column to a SQL query:
https://stackoverflow.com/questions/13550750/how-to-add-row-index-as-a-column-to-sql-select-query
Kevin
Ya, I tried the code you gave in last post but works only after disabling deferRender. I need both deferRender and index column. How could it be achieved.
The example I provided works here:
http://live.datatables.net/qubixihi/1/edit
I updated it to use Ajax data and
deferRender
. Also made a change to use therowLoop
parameter ofrows().every()
. Exporting to Excel has all rows with the index.Please update my test case or provide a link to your page or test case to show the issue.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Thanks, it works