An empty column when ajax sourced

An empty column when ajax sourced

JamaurJamaur Posts: 87Questions: 10Answers: 0

I have an ajax sourced table & I wish to have a column not attached to any object property (no columns.data specified) i.e. an empty column.

The below code throws errors in the console and displays alert. Please note that the first column is set to null.

var table = $('#example').DataTable( {
        "serverSide": false,
        "ajax": "https://api.myjson.com/bins/1frdi",
        "columns": [
            null,
            { "data": "position" },
            { "data": "office" },
            { "data": "extn" },
            { "data": "start_date" },
            { "data": "salary" }
        ]
    } );

Test Case: http://live.datatables.net/letehocu/1/edit

You will probably ask me, why would you need an empty column? Ex: Control column for responsive extension or Check-box column for select extension

Answers

  • JamaurJamaur Posts: 87Questions: 10Answers: 0
    edited September 2015

    Datatable seems to let the user not specify columns.data when setting columns.defaultContent to an empty string (shown below). Is this correct?

    var table = $('#example').DataTable( {
            "serverSide": false,
            "ajax": "https://api.myjson.com/bins/1frdi",
            "columns": [
                { "defaultContent": "" },
                { "data": "position" },
                { "data": "office" },
                { "data": "extn" },
                { "data": "start_date" },
                { "data": "salary" }
            ]
        } );
    
This discussion has been closed.