Dynamically get column names in $aColumns arrary in datatables using server side processing

Dynamically get column names in $aColumns arrary in datatables using server side processing

RalZyRalZy Posts: 2Questions: 0Answers: 0
edited December 2012 in General
I cannot present a test case as I am using Codeigniter framework for php and cannot host the page on my own. I've used this https://github.com/blake-nouribekian/codeigniter-datatables to create datatables in CodeIgniter and successfully did it for a single table. Now I have 5 tables. On my display page I'll put 5 buttons for each table and on clicking on any button respective table will be displayed. I want that in Datatable format. Now in server side processing php there is $aColumns array which has to be initialisted with static values of column names of a particular table which is defined in $sTable. I want to make both variables dynamic. On button click their values will change and accordingly the respective Datatable will be displayed. Is this approach correct or I can use some other way ?

I am adding a bit of code of what I am trying to say.

[code]if(isset($_POST['display_marks']))
{
$aColumns = array('student_id', 'exam_id', 'subject_id', 'marks_achieved');
$sTable = 'marks';
}
if(isset($_POST['display_branch']))
{
$aColumns = array('branch_id', 'branch_name');
$sTable = 'branch';
}[/code]

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Its not incorrect I'd say - its one way of doing it! I think its a fine way of doing it as well. If it works for you, go with it.

    Allan
  • RalZyRalZy Posts: 2Questions: 0Answers: 0
    I've achieved this using AJAX request and DOM data source. Works like a charm !
This discussion has been closed.