fnRender not invoked on fnDeleteRow

fnRender not invoked on fnDeleteRow

OdinOdin Posts: 4Questions: 0Answers: 0
edited February 2013 in General
Hi,

I use the fnRender feature to display the row number in a column.

It works well when I dynamically add a row (via fnAddData). However when I delete a row (via fnDeleteRow), fnRender is not invoked.

Is it a bug ? Another approach ?

Any help would be appreciated

jquery.dataTables.js: 1.8.2

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Why would fnRender be used when deleting a row? You delete it, so why would it render anything?

    Having said that, fnRender is deprecated and shouldn't be used. it will be removed in v1.10. Use mRender instead.

    Allan
  • OdinOdin Posts: 4Questions: 0Answers: 0
    Indeed, but in my case I want to update the numbers of the other rows in the table when a row is added or deleted.

    I'm not sure what's the best place to implement it; fnDrawCallback I guess.

    Thank you
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    So you want fnDeleteRow to call fnRender on all other rows?

    You'd need to call fnUpdate on all of the other rows, since you are updating those rows.

    Allan
  • OdinOdin Posts: 4Questions: 0Answers: 0
    edited March 2013
    Hi,
    I upgraded to jquery.DataTables 1.9.4.
    I migrated my fnRender stuff to mData and mRender.
    I moved the 'row number' logic to fnRowCallback.

    Now the problem I'm encountering is that my datasource is an array of integers and mData expects an object, not a primitive.

    So to circumvent this, I have to wrap my primitives like this:

    function wrapElementsOf(array) {
    var wrapped = [];
    for (var i = 0; i < array.length; i++) {
    wrapped.push({"value": array[i]});
    }
    return wrapped;
    }

    Thanks
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    > Now the problem I'm encountering is that my datasource is an array of integers and mData expects an object, not a primitive.

    mData should work just fine with primitives. Can you link me to an example which doesn't work?

    Allan
  • OdinOdin Posts: 4Questions: 0Answers: 0
    http://jsfiddle.net/aPQPQ/7/
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    I see what you mean now, thank you for the test case.

    Two issues here:

    > mData: ""

    Is meaningless. If you want `data` in the mRender method to take the value of the data source object, you should use `null` .

    The other issue is that DataTables 1.9- doesn't support this kind of data - it requires objects or arrays as the data source object.

    However, DataTables 1.10 which is currently in development has lifted that restriction, as you can see here: http://jsfiddle.net/aPQPQ/8/ (I've cheated and just used the file from Github, you shouldn't do that in anything other than a simple test like this!).

    Although 1.10 is in development, it has that change in it can you can use it now.

    Allan
This discussion has been closed.