0

I am using the datatables jquery plugin. I am trying to use it as a shared function so that I can call a datatable from numerous pages without putting a huge amount of code on each page.

So I am trying to make a variable for the columns that get passed to the datatables function:

var columnsObj = {"columns": [
    {"sName": "first_name","sTitle": "First Name","bSearchable": "true"},
    {"sName": "last_name","sTitle": "Last Name","bSearchable": "true"},
    {"sName": "email","sTitle": "Email","bSearchable": "true"}
]};

How would I take the above code and place that into the datatables function below properly?

Do i need to loop over the object? Or can I just include it somehow like below?

oTable = $("table.datatable").dataTable({
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "getjson.cfc?method=tableData",
    "aoColumns": [columnsObj]
});

1 Answer 1

2

You can access columns as a property on columnsObj.

'aoColumns': columnsObj.columns

(just to be thorough, you can also access it by it's string name too as an indexer...

'aoColumns': columnsObj['columns']

)

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

1 Comment

Wow, that was a lot simpler than I thought. Thanks!

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.