How to programmatically set template attribute in Editor 1.6?

How to programmatically set template attribute in Editor 1.6?

daveslabdaveslab Posts: 40Questions: 14Answers: 0

Hi folks,

Is there a way to set and unset (above all) the new template attribute for a Datatables Editor instance? I have a table which changes columns drastically depending on it's usage and I would like to use a template for its editor depending on certain conditions. Is this possible?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    Answer ✓

    Currently no - sorry. That is not something I had thought of before. Currently the template can only be set at initialisation time, but there shouldn't be any technical barrier to being able to create an API so it can be changed. I'll look into that and hopefully make it available in 1.6.2.

    Regards,
    Allan

  • daveslabdaveslab Posts: 40Questions: 14Answers: 0

    Thanks for your response and thanks for thinking about integrating this, Allan!

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    Just a quick follow up on this. I've committed a new template() method that will be available in Editor 1.6.2 which I hope to release later this week.

    Regards,
    Allan

  • daveslabdaveslab Posts: 40Questions: 14Answers: 0

    Cool, thanks a bunch Allan !

  • yajrayajra Posts: 16Questions: 1Answers: 1

    Allan, I think there is a bug on template() method. It works on the first load of form but succeeding calls display empty form.

    $('#projects-table').on('click', '.edit-status', function (e) {
      e.preventDefault();
      editor.template('#project-status-form')
        .edit($(this).closest('tr'), {
            title: 'Set Project Status',
            buttons: [
                { text: 'Save', className: 'btn btn-primary', action: function () { this.submit(); } },
                { text: 'Cancel', className: 'btn btn-secondary', action: function () { this.close(); } }
            ]}
        );
    });
    

    The code above works on the first click/edit of row. However, clicking the next edit button, the modal will display with empty form. ATM, my workaround is to create a duplicate editor form with a different template. Thanks!

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    Hi @yajra. What version of Editor is it that you are using? 1.7.4 should work with that.

    Thanks,
    Allan

  • yajrayajra Posts: 16Questions: 1Answers: 1

    Hi @allan, I am using 1.7.4. Have been testing it multiple times and just tried again today. It does work only on first call but succeeding calls returns an empty form.

    Attaching a sample form image.
    Below is the first click.

    Here is the next call onwards.

        oTable.on('click', '.editor-edit-budget', function (e) {
            e.preventDefault();
            editor.template('#project-budget-form').edit($(this).closest('tr'), {
                title: 'Update Project Budget',
                buttons: buttons
            })
        });
    
  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    Interesting. Do you have a page you can give me a link to so I can trace it through?

    Allan

This discussion has been closed.