admin管理员组文章数量:1405577
I need to create a function to filter data according to time.
I have a table of flights with departure time in related rows, what i need is, i will put to time filter fields to my form, for hiding flights before and after selected time. In other words, flighs bettween selected time interval will be visible.
I have no problem with getting time info from table and my inputs, but i do not now how to pare them. I use jquery.
I need to create a function to filter data according to time.
I have a table of flights with departure time in related rows, what i need is, i will put to time filter fields to my form, for hiding flights before and after selected time. In other words, flighs bettween selected time interval will be visible.
I have no problem with getting time info from table and my inputs, but i do not now how to pare them. I use jquery.
Share Improve this question edited Dec 25, 2014 at 10:39 Mp0int asked Jul 23, 2010 at 7:52 Mp0intMp0int 18.8k16 gold badges87 silver badges118 bronze badges 02 Answers
Reset to default 7No need for jquery on this one. Just plain old javascript.
The easiest way is to just convert the date objects to unix time using getTime method (I think that is the name). Then just do a greater/less than parison to see if the values are within the range.
The easiest and fastest way of doing client side data manipulation (sorting, filtering, grouping) is jOrder.
In your case, I assume the data looks something like this: (date1 and date2 being date objects)
var data = [{flight: '776', departure: date1}, {flight: '51', departure: date2}];
First thing, create a jOrder table out of the array, with index on departure time.
var table = jOrder(data)
.index('departure', ['departure'], {grouped: true, ordered: true});
Then, you can easily select the row with dates in the specified range.
var hits = table.where([{ departure: {lower: datelow, upper: datehi}}], {mode: jOrder.range});
Finally you can rebuild or modify the UI objects according to the hits.
jOrder is available at http://github./danstocker/jorder.
本文标签: Compare time in javascriptStack Overflow
版权声明:本文标题:Compare time in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744304699a2599752.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论