0

I am designing an application which is using a predefined library from DataTables to create the data table. I want to perform remove operation on Datatable, for which java script should get executed on button click event.

$(document).ready(function() {
    var table = $('#example').DataTable();
    $('#example tbody').on( 'click', 'tr', function () {
        if ($(this).hasClass('selected')) {
            $(this).removeClass('selected');
        }
        else {
            table.$('tr.selected').removeClass('selected');
            $(this).addClass('selected');
        }
    });

    $('#button').click(function() {
        table.row('.selected').remove().draw(false);
    });
});

HTML button is:

 <button type="button" class="btn btn-primary btn-sm">Remove</button>

Clicking this button should execute above script and the selected row should get deleted from the datatable.

1
  • by datatable do you mean to say you are using a jquery plugin datatables? Commented May 30, 2015 at 7:02

2 Answers 2

1

You need set the id(identifier) of button since you are using ID Selector ("#id")

<button id="button" type="button" class="btn btn-primary btn-sm">Remove</button>
Sign up to request clarification or add additional context in comments.

Comments

0

you are not actually selecting the right button . ways to select

1>To select the button either add "id='button'" without quotes in the html or 2>user your class to select the button if it is unique.

though both will work, first one is recommended.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.