1
votes

I need to filter results between start date and end date selected by datepicker using reference http://linqjs.codeplex.com/ how can I filter based on my calendar inputs.

start date : $('#startdate').val() // MM/DD/YYYY format

end date : $('#enddate').val() // MM/DD/YYYY format

var queryResult = $.Enumerable.From(jsonResultTble) 
.Where("??") 
.ToArray();

Sample Data:

var jsonResultTble = [{"ItemId":3,"Condition":"Very Good","Seller":"[email protected]","Rating":0,"School":"University of California-Los Angeles","City":" ","State":" ","Comments":"N/A","RetailPrice":0,"ManufactureDate":"4/10/2012 12:00:00 AM","ExpiryDate":"4/10/2014 12:00:00 AM"},{"ItemId":4,"Condition":"Very Good","Seller":"[email protected]","Rating":18,"School":"Mississippi Valley State University","City":" ","State":" ","Comments":"N/A","RetailPrice":0,"ManufactureDate":"1/10/2010 12:00:00 AM","ExpiryDate":"4/10/2016 12:00:00 AM"]; 
1
Can you include an example of the jsonResultTble?Faris Zacina
Thanks ZenCoder.I have added a sample.Please notice it has time also.Although it can be ignored.user2118542
You got an answer.. let me know if you need anything more.Faris Zacina
@coder Check this out: neue.cc/reference.htmPascal

1 Answers

1
votes

You can do the following to filter based on a date range:

var startDate = "1/10/2010";
var endDate = "4/10/2010";

var queryResult = Enumerable.From(jsonResultTble)
    .Where(function (x) { return x.ManufactureDate >= startDate && x.ManufactureDate <= endDate })
    .OrderBy(function (x) { return x.Seller })
    .Select(function (x) { return x.Seller })
    .ToArray();

Here is a jsFiddle for the LINQ.js:

http://jsfiddle.net/6mchrmn9/5/

If you want to get rid of the time in the json, instead of x.ManufactureDate you can re-format the code using something like:

new Date(x.ManufactureDate).format("dd/m/yyyy");

The format function does not exist natively on the prototype, so check out:

http://jsfiddle.net/phZr7/508/