18

I'm using jquery datatables and I have some <tr> inside a table with the following structure:

<tr class="odd">
     <td class="  sorting_1">0</td>
     <td class=" ">2011</td>
     <td class=" ">20</td>
     <td class=" ">
         <span class="btn-group">
            <a class="del btn btn-small" href="#"><i class="icon-delete"></i></a>       
         </span>
     </td>
</tr>

I writed the following jquery code for deleting the row associated to the button I click on.

$(".del").bind("click", function(event){
        var target_row = $(this).parent().parent().parent();
        var aPos = oTable.fnGetPosition(target_row); // the error occurs here!
        oTable.fnDeleteRow(aPos);
          });

but I obtain an error like this:

"TypeError: a.nodeName is undefined" in jquery min script file.

EDIT:

Here the code for creating datatables:

if( $.fn.dataTable ) {
            $(".mws-datatable").dataTable();
            var oTable = $(".mws-datatable-fn").dataTable({
                bRetrieve: true,
            sPaginationType: "full_numbers"
            });
        }
3
  • please post whole of your relevant jQuery code :) and try including jquery from Google APIs and see it it works Commented Jul 6, 2013 at 16:21
  • What is the logic inside fnGetPosition function? Commented Jul 6, 2013 at 16:25
  • I have already tried using Google APIs cdn, but it does not works. @Hearaman here you can find the logic og fnGetPosition: datatables.net/ref#fnGetPosition Commented Jul 6, 2013 at 16:26

2 Answers 2

54

I solved the problem using this code:

$(".del").bind( "click", function(event) {
    var target_row = $(this).closest("tr").get(0); // this line did the trick
    var aPos = oTable.fnGetPosition(target_row); 

    oTable.fnDeleteRow(aPos);
});
Sign up to request clarification or add additional context in comments.

Comments

2
$().ready(function () {
  $('body').on('click', '#deletebtn', function () {
    $("#example1 tr").each(function () {
      var rowSelector = $(this);

      if (rowSelector.find("input[type='checkbox']").prop('checked')) {
        rowSelector.remove();
      }
    });
  });
});

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.