mDataProp (Dynamic column properties) using Serverside Processing

mDataProp (Dynamic column properties) using Serverside Processing

johnadamsyjohnadamsy Posts: 13Questions: 0Answers: 0
edited February 2012 in General
Hi Allan,

Glad to have made greater progress with this plugin.
I am using multiple tables on a single page, and I don't want to keep rewriting this part or rather the whole datable initialization code:
[code]"aoColumns": [
{ "mDataProp": "engine" },
{ "mDataProp": "browser" },
{ "mDataProp": "platform" },
{ "mDataProp": "version" },
{ "mDataProp": "grade" }
][/code]

I have seen the function, but it rather, doesn't bring out the concept clearly...How would I use javascript to define the columns dynamically...table x has the following column definitions [code]{ "mDataProp": "fname" },
{ "mDataProp": "lname" },
{ "mDataProp": "age" },
{ "mDataProp": "dob" },
{ "mDataProp": "grade" }[/code] and another table y have the following:
[code]
{ "mDataProp": "item_code" },
{ "mDataProp": "name" },
{ "mDataProp": "quantity" },
{ "mDataProp": "price" }
[/code]

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    There are a lot of different ways of doing it! The first thing you would need is the information of what the column properties are - likely an array. Then you could do something like:

    [code]
    var my_cols = [ 'fname', 'lname', 'age', 'dob', 'grade' ];
    var cols = [];

    for ( var i=0, iLen=my_cols.length ; i
  • johnadamsyjohnadamsy Posts: 13Questions: 0Answers: 0
    Great thanks! I also tried a cheaper one but may have issues if the page isn't refreshed: using a session ID to write out the columns...like this:
    [code]<?php if($_SESSION['table_name_id']==0){?>
    "aoColumns":[{"mDataProp":"product_id"},
    {"mDataProp":"p_name"},
    {"mDataProp":"p_price"},
    {"mDataProp":"p_quantity"}],
    <?php }else if($_SESSION['table_name_id']==1){?>
    "aoColumns":[{"mDataProp":"ex_id"},
    {"mDataProp":"ex_name"},
    {"mDataProp":"ex_amount"},
    {"mDataProp":"ex_date"}],
    <?php }?>[/code] Though I will try that one as well, as it maximizes on javascript which I was essentially looking for.
This discussion has been closed.