Is there a way to get aocolumns from the server in datatable editable? Is there a way to get aocolumns from the server in datatable editable? ajax ajax

Is there a way to get aocolumns from the server in datatable editable?


It doesn't work because you are assigning the return value of $.ajax(...) to aoColumns here (when you actually need to be assigning an array of columns to "aoColumns"):

}).makeEditable({     ...     "aoColumns": $.ajax({

Instead what you need to do is make the AJAX call FIRST. Then, inside the jQuery success function setup your datatable.

$.ajax({    url: '/get_aoColumns',    ...    success : function(data) {        // ToDo: put all your datatable code in here.        // and assign `data` to "aoColumns"            /** data table code **/        }).makeEditable({        "aoColumns": data            /** rest of data table code **/    }

I have tried to leave all but the important bits out to make the key points clear, but this should help you understand where you have gone wrong.

I've set up a JS Fiddle here with an (untested) code sample if this doesn't make sense:

http://jsfiddle.net/GarryPas/got4fxhb/1/


assuming /get_aoColumns is returning everything correctly, it looks like you want to fetch that information first, and then in the success handler, create the datatable. In your code above, it looks like the dataTables declaration can finish before the ajax request has a chance to complete, so how about this:

$(document).ready(function () {    /* Add/remove class to a row when clicked on */    $('#table1 tr').on('click', function () {        $(this).toggleClass('row_selected');    });    var which_table = window.location.pathname;    var which_table_data = which_table.substring(0, which_table.length - 1) + '/data';    var table_name = which_table.substring(14, which_table.length - 1);    //wrap the ajax request to get aoColumns outside of the initializaer    $.get('/get_aoColumns', {q: table_name}, function (aoColumns) {        $('#table1').dataTable({            "bProcessing": true,            "bServerSide": true,            "bjQueryUI": true,            "sAjaxSource": which_table_data,            "bPaginate": true,            "sPaginationType": "full_numbers",            "sScrollX": "100%",            "aoColumnDefs": [{                    "targets": [0],                    "visible": false,                    "searchable": false                }]        }).makeEditable({            "sUpdateURL": "../update/" + table_name,            "sAddURL": "../add/" + table_name,            "sDeleteURL": "../delete/" + table_name,            "aoColumns": aoColumns //the data retrieved from the request to get_aoColumns        });    });});