0

I am trying to add the dynamic column header to data table ,Here is my code for datatable initialisation:

var $table=$('#MSRRes').dataTable
( {
        "bFilter": false,                         
        "bDestroy": true,
        "bJQueryUI": true,
        "ajax" :{
                    url: 'getResult.php',
                    type: "POST",
                    data: {
                        formData:postData,
                        formName:'afscpMsr',
                        action:'advanceSrch'
                    }

                }
});

Following code is for static intialisation of table column header : Customer Name Feature Order No NCP Account Number Mcn Code Sales Person Due Date
(DD/MM/YYYY) No. of SUPs Zonee Id Details

The following code is ajax call to get the datatable result display along with the column names to be display: $result is in json format,$colcond='cust_name,cust_no,mcn_no,sales_contact_name,order_no,COUNT(sup_id),due_date,z.zoned_from_id';

 $newarray = array(
                "draw"            => 1,
                "recordsTotal"    => sizeof($result),
                "recordsFiltered" => sizeof($result),
                "data"            => $result,
                "column"          => $colCond   
            );

            echo json_encode($newarray);
3
  • seen this? Commented Nov 26, 2014 at 15:49
  • I don't think this has anything to do with jquery-ui, hence removing the tag. Correct me if I'm wrong. Commented Nov 26, 2014 at 16:30
  • Yes, jquery ui is not there, Its related to jquery datatables Commented Nov 27, 2014 at 10:23

1 Answer 1

1
var aryColTableChecked = ["column00", "column01", "column02",    "column03","column00","column00","column00","column00"];
var aryJSONColTable = [];

for (var i=0; i < aryColTableChecked.length; i++ ) {
      aryJSONColTable.push({
                "sTitle": aryColTableChecked[i],
                "aTargets": [i]
       });
};

Include this in data table definition :

 var $table=$('#MSRRes').dataTable
( {
    "bFilter": false,                         
    "bDestroy": true,
    "bJQueryUI": true,
    "ajax" :{
                url: 'getResult.php',
                type: "POST",
                data: {
                    formData:postData,
                    formName:'afscpMsr',
                    action:'advanceSrch'
                }

            },
  "aoColumns": aryJSONColTable
});

});
Sign up to request clarification or add additional context in comments.

1 Comment

this solution is working for me, for more information check this link : datatables.net/forums/discussion/11637/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.