hi everyone,
we have requirement to filter the data at view level based on current time. we are using kendo grid.
so trying to use the filters concept.
we have to filter based on enrolldate and term date.
(enrolldate <= currentDate ) && (finaldate ===null or finaldate >= currentdate) ===> Active records
(enrolldate> current date or finaldate < current date) ==> inactive records
try to use the filters but the below scenaio not working:
if the enrolldate is future date and final date is null its throwing as Active records...used below code
if (isactive) {
return {
logic: "or",
filters: [
{
logic: "and",
filters: [
{
field: "enrolldate",
operator: "lte", // check current date also
value: vue360.dateAndTimeToISOString(new Date())
},
{
field: "finaldate",
operator: "gte", // check current date also
value: vue360.dateAndTimeToISOString(new Date())
},
]
},
{
field: "finaldate",
operator: "isnull",
value: null
},
],
};
} else {
return {
logic: "and",
filters: [
{
logic: "or",
filters: [
{
logic: "and",
filters:
[
{
field: "enrolldate",
operator: "gt",
value: vue360.dateAndTimeToISOString(new Date())
},
{
field: "finaldate",
operator: "gt",
value: vue360.dateAndTimeToISOString(new Date())
},
]
},
{
logic: "and",
filters: [
{
field: "enrolldate",
operator: "lt",
value: vue360.dateAndTimeToISOString(new Date())
},
{
field: "finaldate",
operator: "lt",
value: vue360.dateAndTimeToISOString(new Date())
},
]
}
]
},
{
field: "finaldate",
operator: "isnotnull",
value: null
},
],
}
}
Naimish MakwanaPosted Apr 17, 2024, 4:24 AM
I see that you’re trying to filter records in a Kendo Grid based on the
enrolldateandfinaldatefields. You want to classify records as “Active” if theenrolldateis in the past and thefinaldateis either null or in the future. Conversely, you want to classify records as “Inactive” if theenrolldateis in the future or thefinaldateis in the past.The issue you’re facing is that records with a future
enrolldateand a nullfinaldateare being classified as “Active”. This is happening because your “Active” filter logic is considering records with a nullfinaldateas “Active”, regardless of theenrolldate.To fix this, you should adjust your “Active” filter logic to also consider the
enrolldate. Here’s how you can modify your code:In the “Active” filter, I’ve moved the
enrolldatefilter to the top level of theandlogic, so it applies to all records. Theorlogic now only applies to thefinaldatefield, checking if it’s either in the future or null.In the “Inactive” filter, I’ve changed the top-level logic to
or, so a record is considered “Inactive” if either theenrolldateis in the future, or thefinaldateis in the past and not null.Thanks