DataTables Editor - Plugins - Select2: Why not clear the dropdown when needAjax === true?
DataTables Editor - Plugins - Select2: Why not clear the dropdown when needAjax === true?
washuit-iamm
Posts: 136Questions: 57Answers: 2
I noticed that when editing rows back to back, my editor's select2 fields still have the old values. I know I can do update(null) but why is this not done as part of the plugin? Ideally id like a loading dialog.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I have sort of solved the first half of this. If you do
_fieldTypes.select2.update(conf);right before the ajax call it will clear the dropdown.This is because
_addOptionsgets called and thenconf._input[0].options.lengthis set to 0 clearing the options.I still dont have a good way to show a spinner or something.
Final code, put this above the ajax call.
You get the following until the value arrives:
Slightly more advanced, but you can set
loadingTextto HTML if you set your select2 optionsescapeMarkupto not escape markup (see docs). Check out the dots:This was very easy I just grabbed the code snippets from here: https://martinwolf.org/before-2018/blog/2015/01/pure-css-savingloading-dots-animation/
Clearing the old values by default isn't done in the plug-in as it might be that you want to reuse the values. I guess that isn't always true if you are Ajax loading the options, but it is still a possibility.
Great to hear that you've got it working the way you need now.
Allan