Here is an example of the json produced when i set up a date between query in the QueryBuilder:
{
"Condition": null,
"Field": "User Actions.clicks.daterange",
"Label": "Date Range",
"Not": null,
"Operator": "between",
"Type": "Date",
"Value": [
"2023-03-05T00:00:00",
"2023-04-05T00:00:00"
],
"Rules": null,
"RuleId": "querybuilder_group2_rule2"
}
The problem is when I load this json into the QueryBuilder with some code like this:
publicvoidLoadInitialJson()
{
RuleModel ruleModel =Newtonsoft.Json.JsonConvert.DeserializeObject(initialJson);
QueryBuilderObj.Reset();
QueryBuilderObj.SetRules(ruleModel.Rules,"and");
}
it cannot correctly load it and throws an error.
The best overloaded method match for 'System.Collections.Generic.List<System.DateTime?>.Add(System.DateTime?)' has some invalid arguments
using this version
20.3.0.52
I will upgrade and test
Hi Hakop,
Sorry for the delay. We have validated your reported query and kindly refer to the below code snippet to resolve your reported issue.
private void Set() { RuleModel ruleModel = JsonConvert.DeserializeObject<RuleModel>(rule); CustomiseDateType(ruleModel); QueryBuilderObj.Reset(); QueryBuilderObj.SetRules(ruleModel.Rules,"and"); }
private void CustomiseDateType(RuleModel rule) { for (var i = 0; i < rule.Rules.Count; i++) { if (rule.Rules[i].Type == "Date") { List<string> result = new List<string>{}; foreach (var item in rule.Rules[i].Value) { result.Add(item.ToString()); } rule.Rules[i].Value = result; } else if (rule.Rules[i].Type == null && rule.Rules[i].Rules.Count != 0) { CustomiseDateType(rule.Rules[i]); } } } |
Deserialised date value from the json converter is not date or string type, it is like json string. Because of this we got the script error. To overcome this issue, we need to change the json string to default like shown as above code snippet.
Check with above sample code file and get back to us if you need any further assistance on this.
Regards,
YuvanShankar A
thanks, however we will be developing our own version of this component to better fit our needs.
Okay, Hakop. If any assistance is needed for Syncfusion controls, please get back to us.
Hakop,
We are glad to announce our weekly patch release (21.1.0.39) has been rolled out. We have handled the JSON date type string at the source level in this release. Without the workaround, which was provided in our previous update, we can set the rules using the JSON deserialize method. So, we suggest you upgrade our Syncfusion packages to our latest version to resolve this issue on your end (21.1.0.39).