filter: { field: "UserID", operator: "eq", value: e.data.UserID }
I get the following error from oData:
"Operator 'eq' incompatible with operand types 'System.Guid' and 'System.String' Any ideas, The native url requires filter=UserID+eq+guid'ab4e630e-1c7f-49cb-919a-5e82786e753e' .. How can I adjust the filter command to acheive this.
Thanks
12 Answers, 1 is accepted
This can be done like this:
dataSource: {
type:
"odata"
,
serverFiltering:
true
,
transport: {
read:
"<url to the service>"
,
parameterMap:
function
(options) {
// call the default OData parameterMap
var
result = kendo.data.transports.odata.parameterMap(options);
if
(result.$filter) {
// encode everything which looks like a GUID
var
guid = /(
'[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
)/ig;
result.$filter = result.$filter.replace(guid,
"guid$1"
);
}
return
result;
}
}
}
Atanas Korchev
the Telerik team
this works fine as long as strings don't look like guids.
Can you help us extending this functionality to cater for scenarios when some of the strings look like guid-s, but should be strings, and some of the strings are actually guid-s
Thanks,
Stevo
I am sorry but I don't understand your requirements. Could you provide some test data? How are strings that look like guids different than strings that are guids?
Regards,
Atanas Korchev
Telerik
my point is that the code you've provided will replace all filters that look like guids 'xxxx-xxx...' to a 'guid' filter condition (i.e. remove the apostrophes that are used for string filters)
That is the desired behaviour if the .Net Property that you are filtering on is actually of type Guid. However if the property that you are filtering on is of type String, and it contains a string that looks like a guid, the filtering won't work, since the code will remove the apostrophes.
Does that make sense? Just use whatever solution you have to filter on guid, than change your property type to string (make sure the values in there are guids.ToString()) and watch what happens.
Hope that helps,
Stevo
The solution I have given is the only workaround possible. Kendo UI (and JavaScript) don't support a GUID type and this is why a regular expression is needed. Also guids are serialized in JSON as a string.
What I can suggest is to change the regexp so it replaces only strings that fully match a guid (don't just contain a guid):
/^(
'[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
)$/ig;
Regards,
Atanas Korchev
Telerik
exactly, kendoui does not cope with guids in OData. OData is a rich interface, getting more popular, having only 4 data types is not going to work very well.
One way of solving this is if the function kendo.data.transports.odata.parameterMap(options) would be more extensible (i.e. have the ability to override creating filter definition for each filter item), we could support additional data types (like guid) easily.
Also parameterMap arguments don't contain references to the datasource schema model. If we had this, we could extend the schema model with our custom attributes and take them into consideration when creating say the $filter.
Regards,
Stevo
Kendo UI doesn't currently support any of those - you can't override the filter creation and parameterMap doesn't have a reference to the data source model. You may consider opening a feature request in our feedback portal about supporting GUID filtering in OData.
For now the suggestion workaround or creating a new custom transport are the only options possible.
Regards,
Atanas Korchev
Telerik
The following is Atana's hack applied to OData V4:
fixODataV4FilterParameterMap = function (data, type) {
// This is needed for Kendo grid's filters when using OData v4.
// Call the default OData V4 parameterMap.
var result = kendo.data.transports["odata-v4"].parameterMap(data, type);
if (result.$filter) {
// Remove the single quotation marks around the GUID (OData v4).
result.$filter = result.$filter.replace(/('[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}')/ig, function (x) {
return x.substring(1, x.length - 1);
});
}
return result;
};
Hi Robert,
Thank you for suggesting an improvement.
Could you please sign our CLA? Once it is done, please post a comment here and I will forward the PR to a developer from the team.
Regards,
Neli
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hi Robert,
Thank you for signing the CLA. As you could see in the issue there is a reviewer assigned to the PR.
Thank you once again for your collaboration.
Regards,
Neli
Progress Telerik
Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).