How can I access the row inside the ajax url?
How can I access the row inside the ajax url?
ak47
Posts: 16Questions: 5Answers: 2
I'm trying to convert these calls to work against my rest API without an intermediary function on the server. So in order to construct a REST url for, say, an edit operation against a listing, I need to do a PUT request against:
/listings/12345
Where 12345 is the identifier for the listing, and I have that as DT_Rowid for the row that is being edited. What I don't know how to do is append that identifier to the url.
editor = new ($.fn.dataTable.Editor)(
ajax: {
url: "listings/" + ?
method: 'PUT'
data: (d) -> {
model_name: 'listings;
}
}
table: '#listings_table'
fields: [...
This question has an accepted answers - jump to answer
Answers
And of course I can't do this:
Because $('.selected').attr('id') is blank on page load.
Looks like you can use the
ajax()
API to change the URL.Kevin
It works on the DataTable object, but I kept getting:
editor is indeed defined earlier in my Javascript, so, not sure what's going on there.
I found this:
https://editor.datatables.net/reference/option/ajaxUrl
which almost gives me the flexibility I need but unfortunately it's deprecated. I'm trying to hook Editor up against a REST API where I need different urls for each CRUD action, as well as different methods (POST, PUT, DELETE).
The only thing I can think of is I'm going to have to override the ajax of the editor upon click of the New, Edit, and Delete buttons.
Check it out, I got it working. First I add classes to the buttons in the DataTable:
Then I listen for a click on those specific buttons, and set the ajax using different values:
Works across all my controllers automatically in my Ruby on Rails application.
Looks like you are using the
ajax()
API incorrectly. It is different than the Datatablesajax.url()
API. See the example in the docs.Kevin
In Editor's
ajax
option, you can use{id}
in the URL string and Editor will substitute it:There is an example of that available here.
Allan