Changing aoData in fnServerData()

Changing aoData in fnServerData()

DavidBDavidB Posts: 4Questions: 0Answers: 0
edited October 2012 in DataTables 1.8
Hi all,

I'm working with multiple datatables and have written a number of external controls. To achieve this I am populating aoData with extra information and in certain cases changing the default data such as iDisplayLength within the fnServerData() function.

Is there an easier way to achieve this than doing a manual loop of the array and changing the values in each object as I need?

[code]
$.each(aoData, function(key, val){
if (val.name == 'iDisplayLength')
{
aoData[key].value = dt_options.iDisplayLength;
}
});
[/code]

I've scoured the API for setter methods but couldn't find any, I'm sure I'm missing a trick here so any feedback would be great.

Thanks,
Dave

Replies

  • allanallan Posts: 54,701Questions: 1Answers: 8,556 Site admin
    Unfortunately DataTables uses the old jQuery way of a name/value pair (old old jQuery - the "new" way of a simple object is much better). I can't just switch DataTables though as it would completely break backwards compatibility.

    So yes a loop is needed. I'd suggest you use a single function and have something like `pluck( aoData, 'iDisplayLength') rather than an 'each' for every property, but that's the basic idea...

    Allan
  • DavidBDavidB Posts: 4Questions: 0Answers: 0
    I completely understand Allan, a re-write would be huge, thank you for the confirmation and the thoughts. I'll continue on this track.

    Thanks,
    Dave
This discussion has been closed.