Hello,
I am having problem using XamDataGrid V 12.1 while converting specific date filters to equivalent System.DateTime object. I need to fill in the grid from a web-service that requires date range and send messages of that range. I exposed Filter Record and captured the FilterChanged event and would like to request the web-service for the date which user has selected from Filter Drop Down. I didn't able to get the date range exactly but Today, Yesterday, This Week, etc. Can you help me out to transform these strings into equivalent DateTime ojects i.e., start and end dates?
Best
Allana
Hello!
i have the same issue with the filtering of a date column. The parsing approach seems to be working, but isn't realy a beautiful way. Is there devinitive no way of getting a datetime object back from the grid?
Best wishes
Patrick
Hello Allana,
In the RecordFilterChanged event, you can cast e.RecordFilter to a new RecordFilter object. Then, you can obtain the ComparisonCondition from RecordFilterObject.ComparisonConditions[0] as ComparisonCondition. From there, you can obtain the string value from CC.Value.ToString(), where CC is the ComparisonCondition.
The next step is a series of if/else-if statements. I would recommend that the first checks are for the dateTime scope. In other words, check for the string value of the comparison condition containing “Year”, “Month”, “Week”, “day”, etc. Inside each of these if/else-if statements, you will need another series of if statements, which check for the string value containing “This”, “Last”, or “Next.” There are exceptions to this rule with the filters for Today, Tomorrow, and Yesterday, but these can be checked from the initial “un-nested” if statements.
After these checks are done, to get the start and end dates for year and month, you will need to check the DateTime.Today.Year and DateTime.Today.Month properties. For year, you can create two DateTime objects, one of which is the date 1/1/year and the other is 12/31/year. The year variable will depend on which if statement you are in, “This”, “Last”, or “Next.” Month is similar, with the exception of a few other checks that will be needed, such as how many days are in that particular month or if the next or last month was in a different year.
For the weekly filters, you will need to check the day of the week property by utilizing DateTime.Today.DayOfWeek. Then, create a start date for the day of the week that you wish the week to start on, and create an end date that is seven days later by using DateTime endDate = weekStart.AddDays(7).
The quarterly filters will require you to check which quarter DateTime.Today falls into. By definition, the yearly quarters are as follows: Q1 = 1/1/2014 -> 3/31/14. Q2 = 4/1/14 -> 6/30/2014. Q3 = 7/1/14 -> 9/30/2014. Q4 = 10/1/14 -> 12/31/14. For whichever quarter that DateTime.Today falls into, those would be the start and end date times that you would need.
Finally, that daily filters would be rather simple, with Today being DateTime.Today, Yesterday being DateTime.Today.AddDays(-1), and Tomorrow being DateTime.Today.AddDays(1).
I hope this helps you. If you have any other questions or concerns on this matter, please feel free to ask.
Sincerely,AndrewDeveloper Support Engineer IInfragistics Inc.www.infragistics.com/support