Design idea for DT 2 or higher: mData object interface

Design idea for DT 2 or higher: mData object interface

fbasfbas Posts: 1,094Questions: 4Answers: 0
edited August 2011 in General
value elements in aData are currently strings, right? if the code were expanded to allow strings or objects, objects in aData could have their own reference to functions that return values to use in sort, filter, render, etc.

this would allow users to have more complex data in a cell, perhaps HTML code with other DOM elements or wrapper div/span with CSS classes, but specify simple strings to use for the sorting, filtering, etc.

to make it work, a well defined interface should be set up, and any object that codes that interface would be valid. (any object would be valid if object is tested for interface function and toString() is used if interface function not found.)

mData.fnSortString(); // if not found, use oData.toString();
mData.fnFilterString(); // if not found, use oData.toString();
mData.fnRenderString(); // if not found, use oData.toString();
mData.fnTypeString(); // if defined, return sType intented by this mData
etc.

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    [quote]fbas said: value elements in aData are currently strings, right?[/quote]

    In 1.7 this was absolutely correct, but this was relaxed in 1.8 and you can now have any Javascript object or primitive you want in it. Obviously if you are actually displaying the data in the table it needs a way to be displayed (i.e. an object would be shown as "[object Object]"), but you can put whatever you want in now.

    But the basic idea of using fnSortString etc I think is absolutely bob on. I actually started along those lines with 1.8 (the function _fnGetCellData has the parameter "string:sSpecific - data get type ('display', 'type' 'filter' 'sort')" that would would be used for exactly this), and the idea of expanding it to be as you suggest in 2.0 (whenever that happens :-) ).

    Great feedback - thanks!

    Regards,
    Allan
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    maybe a standard initializer function that can be called when Editable returns with a string but you had/want an object. (or call the constructor)
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    To some extent this is already possible since mDataProp can be a function - then when you write (fnAddData / fnUpdate) or read (fnGetData) your function will be called and you can perform whatever actions you need. Since DataTables doesn't have core support for editing there would need to be a little bit of work done to make make the update call when needed, but that is already the case anyway.

    Regards,
    Allan
This discussion has been closed.