question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

General Question: Has anyone implemented 'click row to open edit modal'?

See original GitHub issue

I’m working on removing the ‘Edit’ button from the interface so that the user just needs to click on a row and have it open the edit modal. So far, I’ve done the following:

  • Removed the ‘Edit’ button from the DOM by not declaring dom: 'Bfrtip' in my datatable configuration.
  • Determined the selected row and called openEditModal():
$("[id^='my_datatable_'] tbody").on( 'click', 'tr', function () {
        var tableID = $(this).closest('table').attr('id');    // id of the table, e.g., my_datatable_123
        theDataTable.row(':eq(0)', { page: 'current' }).select();
        $( '#'+tableID )[0].altEditor._openEditModal();
});

The above code opens the edit modal, pre-filled with the datatable data. However, when I edit a field/form input, the changes are not being saved. If I remove my row-click selection functionality and just use AltEditor as designed, my SQL/database code is working and the updates are saved so clearly I’m missing something.

Has anyone implemented a ‘click a row to open an AltEditor modal’? I’m looking for code to review to see if I can determine where I’m going wrong. Thanks.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
luca-vercellicommented, Sep 15, 2020

You can try this:

$(document).delegate("[id^='my_datatable_'] tbody", 'click', 'tr', function () {

    var tableID = $(this).closest('table').attr('id');    // id of the table
    var that = $( '#'+tableID )[0].altEditor;
    that._openEditModal();
    $('#altEditor-edit-form-' + that.random_id)
                .off('submit')
                .on('submit', function (e) {
                    e.preventDefault();
                    e.stopPropagation();
                    that._editRowData();
                });
});

$(document).delegate(...) is performed after on('click', ...) , so row is already selected

0reactions
cdixsoncommented, Sep 15, 2020

Thanks again @luca-vercelli

The $(document).delegate code above works perfectly in my application.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Display specific row data in bootstrap modal with edit button ...
I have tried the solution found on stackoverflow "Pull information from mysql table to bootstrap modal to edit" by link. But could not...
Read more >
Inline editing or modal popup - UX Stack Exchange
Creating a new record, or changing many fields of a record when the total columns are large in numbers. Then it makes sense...
Read more >
How to keep Editor modal window open (single entry) for ...
Hello, I would like to edit a single entry and allow the user to submit the form without it closing thus allowing them...
Read more >
How To Implement a Modal Component in React - DigitalOcean
Build a modal component in your React project using props and state ... Your project will display and close a modal upon clicking...
Read more >
Modal Windows in Service Portal - ServicePortal.io
Below is a simple example of how to open up a modal window: ... I posted some service portal questions on the SN...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found