javascript - Array filter and Array Display -
I have an array and use JQuery to display it in 2 column table. But in some way it is not displayed as expected in 2 columns.
I have 2 text fields to enter the date and date to filter the table, but how do some things do it
please
HTML
& lt; P & gt; From: & lt; Input class = "Datepicker" id = "dateFrom" type = "text" & gt; To: & lt; Input class = "datepicker" id = "dateTo" type = "text" & gt; & Lt; Button class = "buttApply" & gt; APPLY & lt; / Button & gt; & Lt; / P & 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 (); $ ('. ButtApply') Click (function () {var filtered = dateList.filter (function) {return item> $$ ('# dateFrom'). Val () & amp; amp; ; Item & lt; = $ (for '# date'). Val ();}); Refreshable (filtered);}); Var nameList = [{Name: "Mike Jenson", Date: "07/01/2014"}, {Name: "Liz Vanil", Date: "07/02/2014"}, {Name: "Robin Jason" Date: "07/03/2014"}, {Name: "Ellen Green", Date: "07/04/2014"}, {Name: "Dan Gray", Date: "07/05/2014"}, { Name: "Junk Johnson", Date: "07/06/2014"}, {Name: "Kelly Luthor", Date: "07/07/2014"}, {Name: "Rock Root", Date: "07 / 08/2014 "}, {Name:" John Lenin ", Date:" 07/09/2014 "}, {Name:" Michael Jane ", Date:" 07/10/2014 "}]; Add Function Refreshable (List) {$ ("# myTable") .. ("& lt; tr & gt; & lt; td> Name & lt; / td & gt; & lt; td & gt; Date & Lt; / td> & lt; / tr & gt; "); (Var i = 0; i & lt; list.length; i ++) for {var tr = "& lt; tr & gt;"; Var td = "& lt; td>; + List [i] ["name"] + ""; Var td = "& lt; td>; + List [i] ["date"] + " "; $ ('# MyTable') Attachment (tr + td + td); }} Refresh (date list);
Here is the answer to your first problem
But somehow it does not display in expected form in 2 columns Try this loop
var tr = "& lt; tr & Gt; "; Var td1 = "& lt; td>; + List [i] ["name"] + ""; Var td2 = "& lt; td>; + List [i] ["date"] + " "; $ ('# Mytable') enclosed (TR + TD1 + TD2). You did both TDS in the same variable td , so it was writing for the first time. And your second problem for this is because, because you are getting the whole thing, you have to compare it with the date.
Return items. Date & gt; = $ ('# DateFrom'). Val () & amp; Amp; ; Item.Date & lt; = $ ('# DateTo'). Val ();
Comments
Post a Comment