Skip to content

Commit 3c668f6

Browse files
add doc for ajax_update (#2728)
* add documentation for ajax_update Fixes #2401
1 parent a8ea284 commit 3c668f6

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

doc/introduction.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,11 @@ For a faster editing experience, enable **inline editing** in the list view::
256256

257257
column_editable_list = ['name', 'last_name']
258258

259-
Or, have the add & edit forms display inside a **modal window** on the list page, instead of
260-
the dedicated *create* & *edit* pages::
259+
Editable_list is converts each column into Ajax form so that you can edit & save the new value
260+
in same row. see the API docs :meth:`~flask_admin.model.BaseModelView.ajax_update` for Ajax example.
261+
262+
Another way of inline editing without losing the current context, have the add & edit forms display
263+
inside a **modal window** on the list page, instead of the dedicated *create* & *edit* pages::
261264

262265
create_modal = True
263266
edit_modal = True

flask_admin/model/base.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2684,12 +2684,33 @@ def ajax_lookup(self) -> T_RESPONSE:
26842684
@expose("/ajax/update/", methods=("POST",))
26852685
def ajax_update(self) -> None | tuple[str, int] | str:
26862686
"""
2687-
Edits a single column of a record in list view.
2687+
Edits a single column of a record in list view. Usually used with
2688+
`column_editable_list` that integrates with the x-editable library.
2689+
2690+
.. code-block:: javascript
2691+
2692+
// you can use jQuery to make ajax calls like this:
2693+
2694+
$.ajax({
2695+
url: '/admin/<your_model_view_endpoint>/ajax/update/',
2696+
type: 'POST',
2697+
data: {
2698+
"list_form_pk" : "<primary_key_value>",
2699+
"<column_name>": "<new_value>"
2700+
},
2701+
success: function(response) {
2702+
// handle success
2703+
},
2704+
error: function(response) {
2705+
// handle error
2706+
}
2707+
});
2708+
26882709
"""
26892710
if not self.column_editable_list:
26902711
abort(404)
26912712

2692-
form = self.list_form()
2713+
form = self.list_form() # returns a form of all fields
26932714

26942715
# prevent validation issues due to submitting a single field
26952716
# delete all fields except the submitted fields and csrf token

0 commit comments

Comments
 (0)