[SOLVED] Reload table via ajax appending new data to the ajax call

[SOLVED] Reload table via ajax appending new data to the ajax call

ttonittoni Posts: 1Questions: 1Answers: 0
edited January 2015 in Free community support

I've got a table listing all the Orders in my database, hence the DataTable instance is fed from server. Orders are attributed with one status: "New", "Accepted", "Cancelled", "Closed".

At the bottom of my table I've got one button for each of those statuses.

I was trying to redraw the contents of my Datatable at the click of one of the filter buttons. In other words I want to request again the contents via ajax and add the clicked status filters to the ajax request.
Like this:

dtable = $('table.dataTable').dataTable({
  ...
  fnServerParams: (aoData) ->
    aoData.push { status: $('a.btn.toggled').data('status') }  // obtain the currently clicked button "data-status"
  ...
})

Problem

aoData is of Object class, therefore the method .push() cannot be called upon it.

Solution

Use bracket syntax:

dtable = $('table.dataTable').dataTable({
  ...
  fnServerParams: (aoData) ->
    aoData['status'] = $('a.btn.toggled').data('status')
  ...
})
This discussion has been closed.