How to reload an ajax link in an editor?

How to reload an ajax link in an editor?

eventimeeventime Posts: 3Questions: 2Answers: 0
edited December 2023 in Free community support
editor = new $.fn.dataTable.Editor({
                    ajax: {
                        url: someurl,
                        data: somedata
                    table: '#table',
                    idSrc: "id",
                    fields: [
                        {
                            label: somelable, 
                            name: somename,
                            type: 'datatable',
                            editor: stuff_editor,
                            optionsPair: {
                                value: 'id',
                            },
                            config: {
                                ajax: someurl',
                                columns: [
                                    {
                                        title: title1,
                                        data: data1
                                    },
                                    {
                                        title: title2,
                                        data: data2
                                    },
                                ],
                            }

I want to reload 'somelable' s ajax after 'stuff_editor' s submission, how can I write the code?

Answers

  • allanallan Posts: 63,438Questions: 1Answers: 10,459 Site admin

    You could use the submitComplete event:

    editor.on('submitComplete', function () {
      table.ajax.reload();
    });
    

    That shouldn't be needed though. The response from someurl should contain the data that is needed to update the table after the edit. That is what happens in the examples.

    Allan

  • eventimeeventime Posts: 3Questions: 2Answers: 0

    Thank you for the answer. I need to elaborate on my case. The ajax I want to reload is editor.fields[0].config.ajax, trigger by stuff_editor. This is a table in editor, I can't find how to call it. The method you provide seems not work.

  • allanallan Posts: 63,438Questions: 1Answers: 10,459 Site admin

    Oh I see - sorry. You can use the dt() method of the datatable field type to get the DataTable instance.

    i.e. do this:

    editor.field('somename').dt().ajax.reload();
    

    Allan

Sign In or Register to comment.