Add row to top of the table rows

Add row to top of the table rows

sd_zuosd_zuo Posts: 78Questions: 1Answers: 0
edited August 2010 in General
I wanna add some editability to DataTables. In the interface in our design, users are supposed to click a "Add new record" item when they want to add one. In our design, no matter how a user sorts a table, the row added is supposed to always appear at the first row, so the user knows a row is added when he clicks the button. And afterward, he can click the row and edit it in-place.
The users can add several rows at a time, and the newly added data won't be submitted to the server-side unless the "Submit changes" button is clicked.

The first problem here is fnAddData does not do the job since there's no means to add the row to the top.
The second problem is to bypass the sorting when a new row is added.
The third problem is to identify those newly added rows, and post the data back to the server.

Is it possible to achieve this?

The data source is a JSON array pulled from a database server.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    1. Ordering in DataTables is always done by sorting. So if you want something to appear at the top, you need to make sure that it is top of the order when sorting. One way of doing this is to write a sorting function which will place your special row always at the top - or you can try a string such as 'aaaaaa' (although that of course won't work when sorting desc). Another option is to inject a temporary row, over which DataTables has no control, at the top of the table. This will be removed whenever there is a redraw.

    2. See above.

    3. fnAddData (will return and array of the internal cache indexes of the rows which has been added). This can be used to get the data - although you already have this at the point of adding the row, so this might not be needed.

    Allan
This discussion has been closed.