Add Row To Datatable at Runtime


#1

Can someone please point me in the right direction.

I have looked at the DataTables website and found what I think is the right thing: https://datatables.net/examples/api/add_row.html

I’ve studied the including sample file, but with no code to add rows I’m just trying different things and wasting a lot of time.

My code at the moment, which isn’t working looks like this.

Function FillDataTable()

    dt.settings.columns = columns1
    dt.settings.data = data1
    dt.build()
    
End Function


Function Button2_onclick()
  table = $("dt").DataTable()
  $(table.row.add(["a","b","c","d"]).draw)
  
  FillDataTable()
End Function

Any help appreciated. I know DataTables is a big topic and NSBasic can’t cover everything, but some more examples on using the datatable would be great.


#2

Afer a couple of hours of mucking around, this seems to achieve what I want, hopefully it helps someone else out:

I’m using BASIC, so it’s wrapped in Javascript

Function Button2_onclick()
   
  JavaScript
    var t = $('#dt').DataTable();
    t.row.add( [
        'data',
        'data 2',
        'data 3',
        'data 4',
    ] ).draw( false );

    counter++;
  End JavaScript

End Function