How to handle situations to convert ooData to aoData
How to handle situations to convert ooData to aoData
greendeveloper
Posts: 4Questions: 0Answers: 0
Hi. I'm stuck in a current quandry at the moment in developing my website. I am using DataTables to display certain responses from my database and give the user more control over interaction. A major update was made to the database and it is no longer returning arrays of objects that DataTables normally would use to parse and construct rows out of. This update was necessary for other elements of the site to work more efficiently, but I really want to make DataTables work with it as well.
Is there any built in feature of DataTables that fires immediately upon success of an ajax request that I could use to convert this object to a format that DataTables would actually accept?
Thanks for any help I can get.
Is there any built in feature of DataTables that fires immediately upon success of an ajax request that I could use to convert this object to a format that DataTables would actually accept?
Thanks for any help I can get.
This discussion has been closed.
Replies
How is the data now being returned? An object?
Allan
Yeah, the data is returned as an object of the rough form:
[code]
{ "data": {
obj1: {stuff},
obj2: {stuff},
//etc
}
}
[/code]
Currently, I'm copying data over and forming a new object from scratch, but I know that won't be feasible as the results list keeps growing over time. I'll try to find some more efficient way of handling it, but I can also find tips on that in other forums.
Thanks Allan!
[code]
var data = $.map( json.data, function (el, idx) {
return el;
} );
[/code]
And then feed `data` into DataTables, since DataTables expects an array.
Allan