Server side processing - Server/Client column independance

Server side processing - Server/Client column independance

mcgrevymcgrevy Posts: 35Questions: 0Answers: 0
edited November 2012 in General
I want to have my server side and client side processing as independant of each other as possible. I have to a large extent got this but a few gliches have appeared.

1) On the server I return in Jason $data['sColumns'] = implode(",", $att); where $att contains my column names that I get from the table definition. This is fine. DataTables handles it.
On the client side I have the same columns defined. Also fine
[code]
"aoColumns": [
//Define all the fields from the server in the order they must be displayed
{"sName":"id"', bVisible:false, bSearchable:false},
{"sName":"type"},
{"sName":"sequence"},
{"sName":"language"},
{"sName":"desc"},
{"sName":"created_at"},
{"sName":"updated_at"},
{"sName":"old_id"},
],
[/code]
BUT now I add a coulmn to the table, the returned Jason $data['sColumns'] has an extra column. Bang - get the "unknown parameter 'aaa' from data source..." error. Can I do something to fix this. I don't want to have to change code just because I have added a database column.

2) I need either the name or id set in the cells. The above code doesn't set either at the cell level. If I use mData it is set but I loose my server/client independance. Get the 'Unknown' error again. Any ideas? Ideally sName should set the id at cell level :)

3) I 'order by' in my sql query. I would like to set aaSorting array from the server so that I get the funky little arrows etc. Is this possible? I use the same layout with different sort sequences for different circumstances. Also it is my intention to allow the users to specify the sequence they want at run time and then save it. I am after all producing a 'package solution'

Replies

  • mcgrevymcgrevy Posts: 35Questions: 0Answers: 0
    Problem (1) above is not quite as simple or as bad as I thought.
    if you comment out a field in the middle of aoColumns eg. {"sName":"language"}, you will get the error but if you remove fields from the end then is OK. So you must define all fields up to and including the last one you want. The error will occur when it is looking for the last field in sColumns (I think)
  • mcgrevymcgrevy Posts: 35Questions: 0Answers: 0
    Solution for problem 1
    In your Laravel action use lines of code similar to this;
    $p = Input::all();
    $rows = Type::get(explode(',', $p['sColumns']));
    This has the additional advantage of only getting what you need, no more.
  • mcgrevymcgrevy Posts: 35Questions: 0Answers: 0
    Solution for problem 2
    var $aoC = $('#examle').DataTable().fnSettings().aoColumns,
    $aoColumns = [];
    for($i=0; $i<$aoC.length; $i++) {
    $aoColumns[$aoC[$i].sName] = $i;
    }
    This will give an array of name/index pairs to use in the JS code
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    > I want to have my server side and client side processing as independant of each other as possible.

    Use mData (mDataProp as it is known in the server script). That allows you to completely separate array order, and data shown in the table from what is given in the JSON.

    Allan
This discussion has been closed.