0

i using jquery datatables , i have 2x table with aoColumns option and 1x without aoColumns

so i want do the following

if(aoColumns != false)
add option in array

i tried that but it didnt work

function Data_Table_Function(file,Language,ServerParams,Row_Call_Back,pagation,columns_sort,aoColumnDefs){
var  Options_Data_Table = {};

Options_Data_Table = {
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": file,
        "sPaginationType": "full_numbers",
        "bPaginate": true,
        "oLanguage": Language,
         "iDisplayLength": 25,
         "aLengthMenu": [
            [10, 25, 50, 100, -1],
            [10, 25, 50, 100, "الكل"]
        ],
        "fnServerParams": ServerParams,
        "aaSorting": [[ 0, "desc" ]],
        "fnRowCallback": Row_Call_Back,
        "fnDrawCallback": pagation,
        "bInfo": false,
        "aoColumnDefs":aoColumnDefs
    };

    if(columns_sort)
    Options_Data_Table.push("aoColumns" : columns_sort);    


return  Options_Data_Table;
}

3 Answers 3

1

Options_Data_Table is object, not array:

Options_Data_Table["aoColumns"] = columns_sort;

OR

Options_Data_Table.aoColumns = columns_sort;  

should work.

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

Comments

0

You can't use push when it comes to objects (as it is a method exclusive to arrays).

Use:

Options_Data_Table.aoColumns = columns_sort;

instead.

Comments

0

The problem is that Options_Data_Table is an object, not an array. In javascript arrays are declared with: [ ]

Documentation about javascript arrays: http://www.w3schools.com/js/js_obj_array.asp

The correct way for add that property is:

Options_Data_Table.aoColumns = columns_sort;

Comments

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.