fnDraw not working as expected with jsArray data source

fnDraw not working as expected with jsArray data source

TehNrdTehNrd Posts: 3Questions: 0Answers: 0
edited August 2013 in General
Go to this example page, http://datatables.net/release-datatables/examples/data_sources/js_array.html , and edit the contents of a cell using the browsers inspector tool. Enter something random like 'test123'.

Now in the browsers console execute fnDraw on the table: $("#example").dataTable().fnDraw();

I would have expected 'test123' to be replaced by the original value that is still stored in the jsArray but this did not happen. Why and how can I get the table to reset/update based on the original data in the jsArray.

Thanks.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Use the fnUpdate API method. DataTables 1.9- takes a copy of the data passed in, so changing the data array makes no difference. This behaviour is changed in 1.10, where you can modify the data directly and then call the new `invalidate` methods to tell DataTables that it needs to update, sorting, filtering and display.

    Allan
  • TehNrdTehNrd Posts: 3Questions: 0Answers: 0
    Thanks for the prompt response Allan. I execute this code on the examples page and it works as expected, the value is reset.

    [code]
    var table = $("#example").dataTable();
    var data = table.fnGetData();

    for(var i = 0; i < data.length; i++){
    table.fnUpdate(data[i],i);
    }
    [/code]

    but when I do this on my own dataTable I get an error:

    [quote]
    DataTables warning (table id = 'jJOqvjLtGuPhjA5fUvaNfA_3D_3D'): Requested unknown parameter '0' from the data source for row 0
    [/quote]

    And console says maximum call stack exceeded.

    Any ideas? I'm stumped.
  • TehNrdTehNrd Posts: 3Questions: 0Answers: 0
    Looks like we where using an older version of dataTables, updating to 1.9.4 appears to have fixed this issue.
This discussion has been closed.