Manually trigger editor edit...

Manually trigger editor edit...

kaustubh.agrawal2000kaustubh.agrawal2000 Posts: 88Questions: 39Answers: 2

I have a use case where, my table has checkboxes (where user can select multiple checkbox and click a button to do some operation)..

Now, the problem is.. I want to disable the edit button if more than 1 checkbox is selected ..

Case 1 :
If the user clicks the checkbox on the header (all the row checkboxes are selected)... in this case the edit button should be disabled if >1 checkbox is selected..

Case 2 :
If user clicks single row checkbox the, edit button should be enabled

Case 3:
If user selects >1 checkboxes in rows, the edit button should be disabled.

I tried with something like below

    $('#sauda').on('click', function() {
        var selectedRows = table.column(0).checkboxes.selected().count();
        if (selectedRows != 1) {
                table.buttons('.buttons-edit').disable();
        } else {
                table.buttons('.buttons-edit').enable();
        }
    });

but this is not working..

Kindly suggest me a good workaround for this.

Answers

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,953

    Are you using the Select extension?

    If so this example shows how to get the selected row count:
    https://datatables.net/extensions/select/examples/api/get.html

    If not then please post your Datatables and JS code for the checkboxes.

    Kevin

  • kaustubh.agrawal2000kaustubh.agrawal2000 Posts: 88Questions: 39Answers: 2

    Hi Kevin.. I am actually using the select plugin...

    but the thing is, I only want to edit button enabled when only 1 row is selected and disabled if 0 OR >1 rows are selected..

    I could not find that inbuilt functionality, so I was trying to do it myself.. but its not working as I have written down in the question.

    Any help on this will be greatly appriciated.

  • kaustubh.agrawal2000kaustubh.agrawal2000 Posts: 88Questions: 39Answers: 2

    The plugin is just awesome ..
    The only thing that I would really request you is to add a few more examples with different use cases that are posted frequently in the forum...

    I always find the answer after extensively searching, but more the examples better it would be for all...

    Having said that,
    Thanks a lot for a great product..!!
    Thanks a lot for a great product..!!
    Thanks a lot for a great product..!!
    Thanks a lot for a great product..!!
    Thanks a lot for a great product..!!

    Also,
    https://datatables.net/forums/discussion/32437/disabled-edit-button-on-multi-row-selection#Comment_87337
    Posting the URL, for someone who lands on this ...

This discussion has been closed.