Multi-Select/ServerSide, Ajax call generates really long urls

Multi-Select/ServerSide, Ajax call generates really long urls

the_macethe_mace Posts: 10Questions: 3Answers: 0

I'm using serverside tables with multi-select and trying to bulk edit items. For my row items, the unique IDs are GUIDs.

When I do the bulk edit and press "Update" it creates a long ajax post with a url like this:

POST '/model/update/c13c8089-f0d4-4022-9736-f17b62e82f3c,43eaf5b8-1eed-4b3c-99d4-e6f408461488,3332cec9-c3f2-45dc-a324-8d463e3805fe'

This was an edit of 3 items. I was expecting the items being editing to be in the POST body and not to generate an extremely long URL.

in the gist, the editor ajax call only specifies a single url/item:

url: "{% url 'people:person_update' '00000000-0000-0000-0000-000000000000' %}"
  .replace('00000000-0000-0000-0000-000000000000', '{id}'),

Its not clear how it decided to extend that to add multiple IDs.

I'd expect it to do some combination of these
1. Have a different (short) URL able to be set for multi-edit
2. Include multiple target items in the POST body
3. Iterate in a loop doing an ajax call for each item edited (wouldnt be great for large counts)

Link to test case:
https://gist.github.com/the-mace/9d91ed950c4288d9837afdf490c0e557

I've searched, read the docs, and have not seen a solution short of rebuilding a bunch of the bulk edit form.

Any ideas?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 62,990Questions: 1Answers: 10,367 Site admin
    Answer ✓

    That's a good question. If you were to not include the id as part of the URL it the server could just read the id from the POST data - it isn't using your REST URLs that way though.

    The only way to do this with the REST URLs would be to use ajax as a function - then either direct it to a different url for a bulk update, or do a looped request (which I agree, should be avoided).

    Allan

  • the_macethe_mace Posts: 10Questions: 3Answers: 0

    Ah this make sense. I wasnt sure why it was building a URL I didnt specify in the ajax url option, but taking out the id completely gives me a POST with the IDs in the body json which I can then process. That looks totally workable.

  • the_macethe_mace Posts: 10Questions: 3Answers: 0

    Update: that worked great and scales. Thanks!

  • allanallan Posts: 62,990Questions: 1Answers: 10,367 Site admin

    Awesome - thanks for the update :)

    Allan

Sign In or Register to comment.