Design idea for DT 2 or higher: mData object interface
Design idea for DT 2 or higher: mData object interface
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.
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.
This discussion has been closed.
Replies
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
Regards,
Allan