javascript - Filter a part of String -


I have an array and shows its data on table

Filter by date or name properly

  1. If someone enters a name, then I write some more code to show "No Data Found", which is not in the list, but in some way Does not work.

  2. Is there a way to write code that will display results if the user only enters the last name or first name, then will the last name or first name be found in that list?

Please put in hand thank you!

HTML

  & lt; P & gt; From: & lt; Input class = "Date picker" id = "dateFrom" type = "text" & gt; To: & lt; Input class = "datepicker" id = "dateTo" type = "text" & gt; & Lt; Button class = "buttApply" & gt; Applicable & lt; / Button & gt; & Lt; / P & gt; Input type = "text" id = "searchByName" & gt; Names are by & lt Search & LT; Button type = "button" id = "byNamebutton" & gt; Search & lt; / Button & gt; & Lt; Span id = "errmsg" & gt; & Lt; / Time & gt; & Lt; Div class = "text" & gt; & Lt; / Div & gt; & Lt; Table id = "myTable" range = "1" width = "300" cellpadding = "5" & gt; & Lt; / Table & gt;  

JS

  $ (".datepicker") .datepicker (); Var dateList = [[Name: "Mike Jenson", Email: "Mike_J @ yesware.com", phone: "9433550193", joined: "05/23/2014",}, {name: "Jim Stevens" Email: "Jim_s@yesware.com", phone: "1299331 9 44", joined: "05/22/2014"}, {Name: "Paul Smith", email: "paul_s@yesware.com", phone : "4351289654", joined: "04/14/2014"}, {name: "Sarah Andrews", email: "sarah_a@yesware.com", phone: "1299332 9 44", joined: "03 / 15/2014 "}, {Name:" Edward O'Brien ", email:" Edward_b_yasser.com ", phone:" 4782456897 ", joined:" 03/27/2014 "}, {name:" Nicole Plano ", email:" nicole_p@yesware.com ", phone:" 6657831564 ", joined:" 03 "Peter_m@yesware.com", phone: "88 93923938", joined: "01/07/2013"}, {name E: "30/2013"}, {name: "Peter Min", email: Aaron Jackson ", email:" aaron_j@yesware.com ", phone:" 6174896315 ", joined:" 04/11/2014 "}]; $ ('# ByNamebutton'). Click (function () {var Namefilter = dateList.filter (function (NameItem) {if (NameItem.name == $ ('# searchByName'). Val ()) {return NameItem.name == $ ('# searchByName ') Val ();;} else {$ (' # mytable ') attached (' no data is found! ') ;.}}); refreshTable (Namefilter);}); . Click on $ ('. ButtApply') (function () {var filtered = dateList.filter (function (item) {return item.joined & gt ;. = $ ('# DateFrom') Val () & amp; Amp; items. & Lt; = $ ('# dateTo'). Val ();}); refreshTable (filtered);}); Function refreshable (list) {$ ("# myTable"). Html (""); (Var i = 0; i & lt; list.length; i ++) for {var tr = "& lt; tr & gt;"; Var td1 = "& lt; td>; + List [i] ["name"] + ""; Var td2 = "& lt; td>; + List [i] ["email"] + ""; Var td3 = "& lt; td>; + List [i] ["phone"] + ""; Var td4 = "& lt; td>; + List [i] ["included"] + " "; . $ ('# Mytable') enclosed (TR + TD1 + TD2 + td3 + TD4); }} Refresh (date list);  

If you want your search by name, by inserting phrases and case sensitive Can Ignore:

  return name IITem.name.toLowerCase (). IndexOf ($ ('# searchByName'). Val (). ToLowerCase ())! = -1; No data was found in the form of  

, you must include it at the end of your refreshable function:

  if (list.length == 0) {$ ('# MyTable'). Html ("no data was found"); }  

JSField:

I would also recommend that your data is not too big to replace your $ ('# byNamebutton'). Code> $ ('# searchByName') for code ( to make it more responsive, as you type filter as


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -