We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

QueryBuilderObj.Rule not updating when changed v47

Thread ID:

Created:

Updated:

Platform:

Replies:

151322 Feb 6,2020 09:50 PM UTC Feb 7,2020 07:16 AM UTC Blazor 1
loading
Tags: Query Builder
Scott Peal
Asked On February 6, 2020 09:51 PM UTC

If you put a query builder on a page with a save button. In the save event the QueryBuilderObj.Rule method is not showing the changed values for Condition nor Rules. 


    protected async void OnClick_Save(MouseEventArgs args)
        {
            // Get the SQL to save to database
            QueryBuilderObj.Refresh();
            RuleModel actRule = new RuleModel()
            {
                Condition = QueryBuilderObj.Rule.Condition,    // Value not updated 
                Rules = QueryBuilderObj.Rule.Rules                    // Value not updated 
            };
            RuleModel rule = await QueryBuilderObj.GetValidRules(actRule);
            string sql = await QueryBuilderObj.GetSqlFromRules(rule);
}

    < EjsDialog Width="80%">
        < DialogPositionData X="Center" Y="Top">
        < DialogTemplates>
            < Content>
                < EjsTextBox @ref="QueryEditorTextbox" Placeholder="Name" @bind-Value="SelectedNode.Name">
                < EjsQueryBuilder @ref="QueryBuilderObj" DataSource="@DataSource" Rule="ImportRules" >
                    < QueryBuilderColumns>
                        < QueryBuilderColumn Field="Name" Label="Name" Type="string">
                        < QueryBuilderColumn Field="Code" Label="Code" Type="string">
                    < /QueryBuilderColumns>
                < /EjsQueryBuilder>
                < EjsButton CssClass="e-primary" @onclick="OnClick_Save">Save
            < /Content>
        < /DialogTemplates>
    < /EjsDialog>

Saranya Dhayalan [Syncfusion]
Replied On February 7, 2020 07:16 AM UTC

Hi Scott, 
 
Thank you for contacting Syncfusion support 
 
We have checked your reported issue, we are not able to reproduce it in our end. Please use the  GetRules method in the button click event. Please find the below code snippet: 
 
@using Syncfusion.EJ2.Blazor.QueryBuilder 
@using Syncfusion.EJ2.Blazor.Buttons 
 
<EjsQueryBuilder Columns="@Columns" DataSource="@EmployeeDetails" @ref="QueryBuilderObj" Rule="@ImportRules"></EjsQueryBuilder> 
<EjsButton CssClass="e-primary" @onclick="setRules">Set Rules</EjsButton> 
 
<EjsButton CssClass="e-primary" @onclick="getSql">Get SQL</EjsButton> 
 
@code { 
        EjsQueryBuilder QueryBuilderObj; 
 
    public List<QueryBuilderColumn> Columns = new List<QueryBuilderColumn> 
{ 
    new QueryBuilderColumn{ Field = "EmployeeID", Label = "Employee ID", Type = "number" }, 
    new QueryBuilderColumn{ Field = "FirstName", Label = "First Name", Type = "string" }, 
    new QueryBuilderColumn{ Field = "TitleOfCourtesy", Label ="Title of Courtesy", Type = "boolean"}, 
    new QueryBuilderColumn{ Field = "Title", Label = "Title", Type = "boolean", Values = new List<string>{ "Mr.", "Mrs." } }, 
    new QueryBuilderColumn{ Field = "HireDate", Label = "Hire Date", Type = "date", Format = "MM/dd/yyyy"}, 
    new QueryBuilderColumn{ Field = "Country", Label = "Country", Type="string"}, 
    new QueryBuilderColumn{ Field = "City", Label = "City", Type = "string"} 
}; 
 
    public List<Employee> EmployeeDetails = new List<Employee> 
    { 
        new Employee{ FirstName = "Martin", EmployeeID = "1001", Country = "England", City = "Manchester", HireDate = "23/04/2014" }, 
        new Employee{ FirstName = "Benjamin", EmployeeID = "1002", Country = "England", City = "Birmingham", HireDate = "19/06/2014" }, 
        new Employee{ FirstName = "Stuart", EmployeeID = "1003", Country = "England", City = "London", HireDate = "04/07/2014"}, 
        new Employee{ FirstName = "Ben", EmployeeID = "1004", Country = "USA", City = "California", HireDate = "15/08/2014" }, 
        new Employee{ FirstName = "Joseph", EmployeeID = "1005", Country = "Spain", City = "Madrid", HireDate = "29/08/2014" } 
    }; 
 
    public class Employee 
    { 
        public string FirstName { get; set; } 
        public string EmployeeID { get; set; } 
        public string Country { get; set; } 
        public string City { get; set; } 
        public string HireDate { get; set; } 
    } 
 
    protected QueryBuilderRule ImportRules = new QueryBuilderRule() 
    { 
        Condition = "and", 
        Rules = new List<RuleModel>() 
            { 
                new RuleModel { Label="FirstName", Field="FirstName", Type="strig", Operator="equal", Value = "Martin" }, 
                new RuleModel { Label="EmployeeID", Field="EmployeeID", Type="string", Operator="equal", Value = "1001" } 
            } 
    }; 
    protected void setRules() 
    { 
        QueryBuilderObj.SetRulesFromSql("FirstName LIKE ('%Ch%')"); 
    } 
    protected async void getSql() 
    { 
        RuleModel actRule = await QueryBuilderObj.GetRules();  
        RuleModel rule = await QueryBuilderObj.GetValidRules(actRule); 
        string sql = await QueryBuilderObj.GetSqlFromRules(rule);           // returns the original ImportRules and not the setRules 
    } 
} 
 
 
Please find the below documentation link: 
 
 
For your convenience we have prepared a sample. Please find the below sample link: 
  
 
Could you please check the above sample and reproduce your reported issue in the above sample and get back to us if you need further assistance on this? 
 
Regards, 
Saranya D 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon