Get datatable 1.10 as jquery object

Get datatable 1.10 as jquery object

MuhaheMuhahe Posts: 25Questions: 8Answers: 2
edited September 2014 in Free community support

Hi, is possible, to get jquery object from datatable variable in 1.10?

If i initialize table like this

var table = '<table id="projects_table">'+
        '<thead>'+
            '<tr>'+
                '<th></th>'+
                '<th>Project ID</th>'+
                '<th>Customer</th>'+
                '<th>Platform</th>'+               
            '</tr>'+
        '</thead>'+
        '<tr><th>0</th><th>1</th><th>2</th><th>3</th></tr>'+
    '</table>';
    
   var dTable = $(table).dataTable();

i get jquery object to variable dTable

but when i use (capital D)

var table = '<table id="projects_table">'+
        '<thead>'+
            '<tr>'+
                '<th></th>'+
                '<th>Project ID</th>'+
                '<th>Customer</th>'+
                '<th>Platform</th>'+               
            '</tr>'+
        '</thead>'+
        '<tr><th>0</th><th>1</th><th>2</th><th>3</th></tr>'+
    '</table>';
    
   var dTable = $(table).DataTable();

I get datatable api. Its way to get jquery object from capital D initialization? Because if i understand well, initialization without capital D is for old datatables. Or am i wrong?

This question has an accepted answers - jump to answer

Answers

  • vogomatixvogomatix Posts: 38Questions: 3Answers: 7
    edited September 2014

    See to$()

    Incidentally your table is just a HTML string and isn't in the DOM when you're creating a datatable api. I suspect this may give you issues.

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Answer ✓

    Because if i understand well, initialization without capital D is for old datatables.

    Not the old DataTables, but rather $().dataTable() and $().DataTable() return different things and both are fully supported. If you want the jQuery object use $().dataTable().

    Allan

  • MuhaheMuhahe Posts: 25Questions: 8Answers: 2

    Thanks for it Allan, my mistake i didnt know it.

    vogomatix: i think it is possible to create datatable on HTML string which ones representig element (before inserting to DOM). In example 1 if i insert dTable into DOM, datatable appears here

This discussion has been closed.