Changing Data

Changing Data

rootmanrootman Posts: 7Questions: 0Answers: 0
edited March 2009 in General
Okay, here I go again!

I know the whole table is stored in an array by the script. What happens if I change the data of a cell without using the provided functions. I wonder how datatables handles it, maybe you can explain it to me Allan, would much appreciate it. I got some examples:

1. I change some data in a cell using jquery functions. Lets say i have a list in a cell and i add another with .append(), will datatables realize the change or do i have to use the update function for the cell? If so, i would lose the ease of jquerys functions like append coz i would retrieve the data with fnGetData as a string and would have to manipulate it. So how should it be done?

2. I delete something out of a cell, lets say i just remove one out of the list. It works just fine using jquery.remove(), but do I have to update the datatables array? will the data come back if the table redraws and i did not update the array?

So just how excactly does it work, is the table redrawn every time from the array (I guess not because when i remove a whole row with .remove() then its gone and doesnt come back, though the count goes wrong) or is the array just a helper to rearrange the table?

Please explain, I'd like to understand how it works so I can produce clean code.




  • rootmanrootman Posts: 7Questions: 0Answers: 0
    Guess found something out, you can alter the display of the table by playing around with the data in the cells, but doing so will not affect the corearray and sorting will work as if you didnt do anything to the table. so you gotta update the corearray to keep it runnin.

    am i right?
  • allanallan Posts: 54,897Questions: 1Answers: 8,605 Site admin
    Hi rootman,

    You are absolutely correct - you can update the DOM if you wish, however DataTables maintains an internal array of the information (mainly for speed optimisation, sorting and filtering direct from the DOM would be seriously slow). So using fnUpdate() will update both the DOM and the internal information in a single call.

This discussion has been closed.