More features with JSON
More features with JSON
Hi
I have made some additions to 1.5.0b9 in order to parse some settings (table header/columns) from the JSON file.
This is my patched dataTables version
http://www.highdefinition.ch/js/jquery.dataTables-1.5.0b9.js
An example is here
https://www.highdefinition.ch/list/Image/LcdTelevision/Sony.html
https://www.highdefinition.ch/dataTables.json?type=list&cat1=Image&cat2=LcdTelevision&manufacturer=Sony
Allan, please consider implementing my changes to _fnInitialise.
Please consider implementing the remaining config options.
Some stuff had be moved around in _fnInitialise.
A loading/processing bar would also be a good thing...
I have made some additions to 1.5.0b9 in order to parse some settings (table header/columns) from the JSON file.
This is my patched dataTables version
http://www.highdefinition.ch/js/jquery.dataTables-1.5.0b9.js
An example is here
https://www.highdefinition.ch/list/Image/LcdTelevision/Sony.html
https://www.highdefinition.ch/dataTables.json?type=list&cat1=Image&cat2=LcdTelevision&manufacturer=Sony
Allan, please consider implementing my changes to _fnInitialise.
Please consider implementing the remaining config options.
Some stuff had be moved around in _fnInitialise.
A loading/processing bar would also be a good thing...
This discussion has been closed.
Replies
Thanks for posting your patched version - looks like quite an interesting idea. So if I am reading your code correctly, basically you can now return column information which is stored in the aoColumns array - right?
There is actually a way of doing this with the current release of DataTables which is a little more flexible:
[code]
$.getJSON( sUrl, null, function( json ) {
$('#example').dataTable( json );
} );
[/code]
With this you can customise the JSON reply to exactly match how you want DataTables to initialise (features, starting parameters etc), so the control of the server-side isn't limited to just the columns. The developer would also have full control over the program to display whatever loading/progress message he/she wants to do.
How does this sound?
Allan
Can u provide an example for getting table headers with json, in a way developer has full control on table header also?
Say some times table has two columns, other times has three... and no change required to page code!!!
BTW, txs a lot for datatables.
Thanks for the tip of doing it the way you proposed but I think my way is cleaner and already implemented so I'll leave it as it is...
@Volvoxe: If you have a look at the demo for creating a DataTable from a JS array ( http://datatables.net/examples/data_sources/js_array.html ) you can see the full JSON object that is required for DataTables to be initialised. This should give you a good starting point. Anything else can be found in the documentation.
Regards,
Allan
Works like a charm.
I did combined two of your samples and got :
[code]
/*Create a table in demo DIV*/
$('#demo').html( '' );
/*Use json to populate created table*/
$.getJSON( sUrl, null, function( json ) {
$('#example').dataTable( json );
} );
[/code]
From example I see
[code]
"aoColumns": [
{ "sTitle": "Engine" },
{ "sTitle": "Browser" },
{ "sTitle": "Platform" },
{ "sTitle": "Version", "sClass": "center" },
{
"sTitle": "Grade",
"sClass": "center",
"fnRender": function(obj) {
var sReturn = obj.aData[ obj.iDataColumn ];
if ( sReturn == "A" ) {
sReturn = "A";
}
return sReturn;
}
}
]
[/code]
This is not a valid JSON. How can I generate it?
Thanks.
Allan
Could you please provide an example?
[code]
aoColumns": [
{ "sTitle": "Engine" },
...
{"fnRender": callToMyFunction}
...
]
[/code]
But I have following problems:
1. This definition is not a valid JSON object, so I can't generate it in a properly way.
2. How can I send additional params to my function (callToMyFunction). I want to have something like this
[code]
function callToMyFunction( oObj, myObj) {
//return String used in display using data from myObj
}
[/code]
3. Is there o possibility to add a user defined property to a column in "aoColumns" definition?
Any help will be appreciated.
Thanks.
Sure I can write an example for you using eval - hit the support button at the top of the page :-)
Allan