Default Datagrid Filter

Hopefully someone can help here.
I have a datagrid that contains deal data from four stores and I need to filter on load based on the store ID and the deals in the current month.

The first part is easy. No problem filtering on the store ID. But filtering on current month seems to be impossible.

I created a property in the load event called defaultMonthID and se the value to DateTime.Now.ToString("MM")

Next I modified the set property event inside the invoke event to read:
${result.Where(r => r.Deals_DealDte.Value.ToString("MM") == defaultMonthID)}

I have tried multiple versions of this and the only thing that works is filtering based on today's date, nut just the month.

Any Ideas???

Hi,
Can u share the error ?

When I run the application, I just get a blank datagrid. No error is generated, which is the frustrating part.

try

${result.Where(r => r.Deals_DealDte.Value.Date.Month == DateTime.Now.Date.Month && r.Deals_DealDte.Value.Date.Year== DateTime.Now.Date.Year)}

It should work

Hi @daveg1466,

I think there is a general issue with the whole way you compare dates. Checking just the month will not return the deals for this month. It will return you all deals that have happened in October (during all years). To get the deals from this month you should compare their date with the beginning of this month! Here is how to get a DateTime object that represents the start of the month: c# - Getting the first and last day of a month, using a given DateTime object - Stack Overflow

Then after you get it you can just use ${result.Where(r => r.DateProperty >= startOfMonth)}

I have to say again that Radzen staff does not provide that kind of support as it isn't Radzen related or even Blazor related - it is a generic business logic requirement of your application.

I strongly recommend debugging your application with visual studio and inspecting with the debugger what the result really is and trying different Where expressions untill the result matches your requirements.

1 Like