Using jQuery DataTables plugin, does fnAddData() add rows to the top or bottom of an html table?

前端 未结 3 2040
梦如初夏
梦如初夏 2021-01-05 11:50

I have tested this and the reason I asked the question is that it seems to be doing different things for different tables.

I couldn\'t find any documentation on if t

3条回答
  •  感动是毒
    2021-01-05 12:11

    Browsing through the source of Datatable, as explained by kgiannakaki. The method will append all new data rows to the end of the table as it should.

    The reason for the "random" behavior, is as each time a new row is added the method will perform a "redraw" of the entire table unless otherwise specified. When this does so the table is run through multiple features such as filtering/sorting etc etc ... and completely rewritten to the page. Essentially I am going to guess you are adding random bits of data into new rows which may be creating the "random" effect, whenever a new row is added.

    You can easily disable table redrawing by adding a second parameter in the fnAddData call which needs to be set to false.

    $(this).fnAddData(data, false);
    

    If this issue still persists I would file a bug for this issue, as their is no other reason for this behavior.

提交回复
热议问题