Is there any way to save extra parameters for ajax in one configuration.

Is there any way to save extra parameters for ajax in one configuration.

asukiaaaasukiaaa Posts: 1Questions: 1Answers: 0
edited September 2017 in Free community support

I succeeded in saving extra parameters for local storage.
However, I called getExtraSearchParams twice.
Is there any way to configure data for ajax.data and stateSaveParams at same time?

Thank you.

<select name="country_id" id="country_id">
  <option value="">please select</option>
  <option value="1">Country A</option>
  <option value="2">Country B</option>
  <option value="3">Country C</option>
</select>

<table id="admin-shops">
  <thead>
    <tr>
      <th>name</th>
    </tr>
  </thead>
</table>
$('#country_id').change(() => {
  dataTable.draw()
})
var getExtraSearchParams = () => {
  return {
    country_id: $('#country_id').val()
  }
}
var initExtraSearchInputs = (ex_params) => {
  if (ex_params === undefined) return
  if (ex_params.country_id) {
    $('#country_id').val(ex_params.country_id)
  }
}
dataTable = $('#admin-shops').DataTable({
  stateSave: true,
  processing: true,
  serverSide: true,
  stateLoadParams: (settings, data) => {
    initExtraSearchInputs(data.extra_search_params)
  },
  stateSaveParams: (settings, data) => {
    data.extra_search_params = getExtraSearchParams()
  },
  ajax: {
    url: "/admin/shops.json",
    data: (data) => {
      data.extra_search_params = getExtraSearchParams()
    }
  },
  columns: [
    {data: "name"}
  ]
})
This discussion has been closed.