jquery-datatables-rails icon indicating copy to clipboard operation
jquery-datatables-rails copied to clipboard

reload dataTable with previous settings

Open hyperrjas opened this issue 9 years ago • 8 comments

In my coffescript files:

table = $("#order_items").dataTable(
    sDom: "<'row-fluid'r>t"
    bProcessing: true
    sScrollX: "100%"
    bScrollCollapse: true
    bAutoWidth: false
    iDisplayLength: 25
    aaSorting: [[1, "desc"]]
    aoColumns: [
      sWidth: "150px"
    ,
      sWidth: "400px"
    ,
      sWidth: "40px"
    , 
      sWidth: "50px"
    , 
      sWidth: "100px",
    , 
      sWidth: "100px"]
    bServerSide: true
    oLanguage:
      sUrl: $('#order_items').data('datatable')
    sAjaxSource: $('#order_items').data('source')
    aoColumnDefs: [
      bSortable: false
      aTargets: ["unsortable"]
    ]).fnSetFilteringDelay()

I create a file update.js.erb and try the next:

table.ajax.reload();

When I try to run update.js.erb, I lose the previous settings. I would like recovery the previous settings to show dataTable with the same appearance, no search box, no counter, no pagination...etc

Thank you

hyperrjas avatar Apr 08 '15 18:04 hyperrjas

I would try updating your initialization to the new API:

table = $("#order_items").DataTable
    dom: "<'row-fluid'r>t"
    processing: true
    scrollX: "100%"
    scrollCollapse: true
    autoWidth: false
    pageLength: 25
    order: [ 1, 'desc' ]
    columns: [
      { 'width': '150px' }
      { 'width': '400px' }
      { 'width': '40px' }
      { 'width': '50px' }
      { 'width': '100px' }
      { 'width': '100px' }
    ]
    serverSide: true
    language:
      url: $('#order_items').data('datatable')
    ajax:
      url: $('#order_items').data('source')
    pagingType: 'full_numbers'
    columnDefs:
      targets: 'unsortable'
      sortable: false
    searchDelay: 350     # <- search throttling replacement for fnSetFilteringDelay()

jh125486 avatar Apr 13 '15 15:04 jh125486

With new api dataTable is not reloaded, Thank you

hyperrjas avatar Apr 13 '15 16:04 hyperrjas

Try $("#order_items").DataTable().ajax.reload() for your reload code in update.js.erb

jh125486 avatar Apr 13 '15 16:04 jh125486

I checked this option and load dataTable with default settings again. Thank you!

hyperrjas avatar Apr 13 '15 16:04 hyperrjas

Awesome, no problem.

jh125486 avatar Apr 13 '15 16:04 jh125486

Hi @hyperrjas, this thread can be closed?

ricardodovalle avatar May 18 '15 03:05 ricardodovalle

No please, I have not yet managed to solve the problem. Thank you

hyperrjas avatar May 18 '15 18:05 hyperrjas

What's the problem you're still having?

jh125486 avatar May 18 '15 18:05 jh125486