Way to row.add() a row at the start without sorting?

Way to row.add() a row at the start without sorting?

MidaIganesMidaIganes Posts: 11Questions: 5Answers: 0

Currently simply doing something like this will put the item as last in the list, ending up several pages deep.
tableTemp.row.add( data.tableRowInfo ).draw();
And unfortunately the data formatting used does not support any kind of a reasonable sort by column.

Replies

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765

    AFAIK you need to use draw() to show the added row which updates the table search and sorting.

    Some options that may help are to use the Absolute sorting plugin. Maybe you can use either the pageJumpTo() plugin or the row().show() plugins.

    Kevin

  • MidaIganesMidaIganes Posts: 11Questions: 5Answers: 0

    Is there no way to have a prepend instead of append situation with this somewhere as it's updating the internal list?

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765

    When using row.add() Datatables will display the row based on the table's sorting which you understand. If no sorting is applied the data is displayed in the order it receives the data set.

    This example shows that row.add() appends the data to the end of the data set. It has ordering disabled so the order is that of the data.
    http://live.datatables.net/ruhakowi/1/edit

    Datatables doesn't have a built-in mechanism to prepend the new rows.

    One option might be to use a timestamp. Use a hidden column for the timestamp and sort descending on this column. You may need to generate a timestamp for the original data set. When using row.add() use Javascript to generate a timestamp for that row.

    Kevin

This discussion has been closed.