javascript - How do I know if there are any rows selected in my datatable? -


i using datatables , validationengine plugin.

my issue able know rows selected on particular page in pagination. so, if have rows selected on second page of pagination , no rows selected on 1st page, show me error 'please select row'.

i have read posts not specific code, that's reason asking question.

so in addition validation code have, should add following code,

code

$("#mselector").on("click", "button[name='next'],button[name='finish']",                function() { var $stepselector = $(".wizardstep:visible"); // current step                  var anyerror = false;                        $stepselector .find("input,textarea,select").each(function () {  if (!$(this).validationengine('validate')) {// validate every input element inside step            anyerror = true;     }   });   if (anyerror)   return false; // exit if error found 

});

});

code

$(function () {         var singleselect =  $('.single-select').datatable({             'lengthmenu': ['300']         });          // single row select         $('.single-select tbody').on('click', 'tr', function () {             if ($(this).hasclass('selected')) {                 $(this).removeclass('selected');                 $('#hid').val('');             } else {                 singleselect.$('tr.selected').removeclass('selected');                 $(this).addclass('selected');                 $('#id').val($(this).attr('id'));             }         });          var cid = $('#hdid').val();          if (cid > 0) {             $("#grid1.single-select")                 .find("[id='" + currentid + "']")                 .addclass('selected');         }          //selection         var mgrid = $("#mselector").datatable({             'lengthmenu': ['300']          });         $('#mselector tbody').on('click', 'tr', function () {              if ($(this).hasclass('selected')) {                 $(this).removeclass('selected');                 $('#mid').val('');              } else {                 mgrid.$('tr.selected').removeclass('selected');                 $(this).addclass('selected');                 $('#mid').val($(this).attr('id'));             }           }); 

code

$("button[name='next'],button[name='finish']").click(function() {   var $step = $(".step:visible"); // current step    var iferror = false;    $step.find("input,textarea,select").each(function() {     if (!$(this).validationengine('validate')) { // validate        iferror = false;     }   });    if (iferror)     return false; // exit if there error }); 

cause

datatables removes non-visible rows dom various reasons when attach event handler works visible elements only.

solution

you need use event delegation providing selector second argument in on() call.

replace code:

$("button[name='next'],button[name='finish']").click(function() {    // ... skipped ... }); 

with

$("#mselector").on("click", "button[name='next'],button[name='finish']", function() {    // ... skipped ... }); 

where mselector table id.

from jquery on() method documentation:

delegated events have advantage can process events descendant elements added document @ later time.

see "direct , delegated events" in jquery on() method documentation , jquery datatables – why click event handler not work more information.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -