javascript - Searching text inside Html table on keyup event of textbox -
i using asp.net mvc 5 bootstrap.js jquery build project.
in 1 of page, there dynamic html generating, html table containing list of employees.
i trying search content below code.
it called on keyup event of textbox.
jquery file refernced here:
@scripts.render("~/bundles/jquery")
event registered @ :
$(function(){ $('#txtfilter').keyup(function(){ filterdata(); }); });
markup:
<div class="popheader"> select employee </div> <br> <span>filter:<input id="txtfilter" type="text"></span> <br><br> <table id="tblsearch" class="table"> <tbody><tr> <th></th> <th> employeeid </th> <th> display name </th> <th> currentusername </th> </tr> <tr><td><a>select</a></td><td>95961</td><td>ankur</td><td>ankurda</td></tr><tr><td><a>select</a></td><td>79761</td><td>sameer </td><td>sameerba</td></tr><tr><td><a>select</a></td><td>91060</td><td>neeraj </td><td>neerajsi</td></tr><tr><td><a>select</a></td><td>83127</td><td>pankaj </td><td>pankajpu</td></tr></tbody></table> function filterdata() { debugger; var $rows = $('#tblsearch tr'); var val = '^(?=.*\\b' + $.trim($(this).val()).split(/\s+/).join('\\b)(?=.*\\b') + ').*$', reg = regexp(val, 'i'), text; $rows.show().filter(function() { text = $(this).text().replace(/\s+/g, ' '); homecoming !reg.test(text); }).hide(); }
whenever type single letter in textbox below error.
error:microsoft jscript runtime error: unable value of property 'tolowercase': object null or undefined.
not able figure out wrong.
remove
@scripts.render("~/bundles/jquery")
and add together jquery this:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
then seek following. may help you.
function filterdata() { var rows = $('#tblsearch tbody tr'); var val = $.trim($('#txtfilter').val()).replace(/ +/g, ' ').tolowercase(); rows.show().filter(function () { var text = $(this).text().replace(/\s+/g, ' ').tolowercase(); homecoming !~text.indexof(val); }).hide(); } });
javascript jquery asp.net-mvc-5
No comments:
Post a Comment