Modify query parameter

Hi support, i'm using the schedule control. 
In my webpage i have:

                <ej-schedule id="Schedule1" width="100%" height="525px" views="views" current-view="Week" show-all-day-row="false"
                             read-only="false" locale="@(System.Threading.Thread.CurrentThread.CurrentCulture.Name)"
                             orientation="Vertical" enable-load-on-demand="true" action-begin="ScheduleBegin">
                    <e-appointment-settings apply-time-offset="false" id="Id" subject='"Subject"' start-time='"StartTime"' end-time='"EndTime"' description='"Description"'
                                            all-day='"AllDay"' recurrence='"Recurrence"' recurrence-rule='"RecurrenceRule"'>
                        <e-datamanager url="/Waitingroom/Schedulings/ScheduleAppointments"
                                       crud-url="/Waitingroom/Schedulings/Crud"
                                       adaptor="UrlAdaptor"></e-datamanager>
                    </e-appointment-settings>
                </ej-schedule> 


In the actionBegin function i have:
        function ScheduleBegin(args) {
            this.model.appointmentSettings.query = ej.Query().from('Schedule').where('Canceled', 'equal', 'false');
            test = this.model.appointmentSettings.query;
        } 

to set my initial query.

Now i would like to chenge the query at runtime to add/remove some parameters dependin on the user choice.

How can i do that?

Another little question why i need to use the UrlAdaptor when my backed is a WebApi ? Because when i use the UrlAdaptor all request to backed are done with POST request and not with GET (for a correct call implementation).

At the same if i don't use the UrlAdaptor the url to manage the CRUD operation not work.

Thanks in advance
Stefano Capobianco

3 Replies

VS Velmurugan S Syncfusion Team April 16, 2018 04:06 PM UTC

Hi Stefano, 
 
Thanks for Contacting Syncfusion support. 
 
Please find the following responses for your queries: 
 
Query #1: Changing the query at runtime 
 
You can change the Schedule control appointmentSettings query at runtime. Please refer to the following code example to meet your requirement. 
 
<Code> 
 
@{ 
    ViewData["Title"] = "Home Page"; 
} 
 
@{ 
    List<string> views = new List<string>() { "Day", "Week", "WorkWeek", "Month", "Agenda" }; 
} 
 
<div> 
    <ej-schedule id="Schedule1" width="100%" height="525px" views="views" current-view="Week" show-all-day-row="false" 
                 read-only="false" locale="@(System.Threading.Thread.CurrentThread.CurrentCulture.Name)" 
                 orientation="Vertical" enable-load-on-demand="true" action-begin="ScheduleBegin"> 
        <e-appointment-settings apply-time-offset="false" id="Id" subject='"Subject"' start-time='"StartTime"' end-time='"EndTime"' description='"Description"' all-day='"AllDay"' recurrence='"Recurrence"' recurrence-rule='"RecurrenceRule"'> 
            <e-datamanager url="Home/GetData" crud-url="Home/Batch" adaptor="UrlAdaptor"></e-datamanager> 
        </e-appointment-settings> 
    </ej-schedule> 
</div> 
<div> 
    <ej-drop-down-list id="selectUser" target-id="usersList" width="200px" watermark-text="Select a User" change="dropValueChange"></ej-drop-down-list> 
    <div id="usersList"> 
        <ul> 
            <li>Admin</li> 
            <li>Guest</li> 
        </ul> 
    </div> 
</div> 
<script> 
    var isQueryChanged = false; 
 
    function ScheduleBegin(args) { 
        if (!isQueryChanged) { // Here checking this value to prevent the below query update to Schedule appointmentSettings 
            this.model.appointmentSettings.query = ej.Query().from('ScheduleAppointment').where('Recurrence', 'equal', 'true'); 
            test = this.model.appointmentSettings.query; 
        } 
    } 
    function dropValueChange(args) { 
        var name; 
        if (args.value === "Admin") { 
            name = args.model.text; 
        } else { 
            name = null; 
        } 
 
        var obj = $("#Schedule1").data("ejSchedule"); // object for schedule is created 
        var dataManager1 = ej.DataManager({ 
                    url: '@Url.Action("GetData","Home")', 
                    crudUrl: '@Url.Action("Batch", "Home")', 
                    crossDomain: true 
                }); 
        var query = ej.Query().addParams("Value", name); // By using addParams we can send the parameter to controller for filtering        
 
        isQueryChanged = true; // Need to maintain this value to prevent appointmentSettings.query value updating in ScheduleBegin event 
 
        if (!ej.isNullOrUndefined(obj)) 
            obj.option("appointmentSettings.query", query); // here we are assigning the query to schedule 
 
         
    } 
</script> 
 
</Code> 
 
We have prepared the sample with the above code example, which can be downloaded from the following location. In this below sample, we have used the DropDownList control to maintain the User type (ex: Admin, Guest) and based on the selection, passed the selected value (if admin) as extra params in the query and assigned to the Schedule appointmentSettings. 
 
 
Query #2: Why i need to use the UrlAdaptor? 
 
We recommended you to use the WebApiAdaptor, as it will be working fine when the CRUD operations are performed on normal appointments, but not processing properly with the recurrence appointments due to the batch process taking place. Since, the batch editing will get performed, while editing the recurrence appointments and therefore, facing issues in that case. Currently, we are analyzing that scenario and will update the further details on this by 20th April, 2018. 

Regards, 
Velmurugan


SC Stefano Capobianco April 17, 2018 02:21 PM UTC

Hi Velmurugan, your solution work very well. I've changed a little bit to use a where using the ej.predicate to add some conditions.

I would like to know if it's possible to do the same for a grid. If it's possible to change at runtime the ej.quey where.

Thanks in advence
Stefano Capobianco


NR Nevitha Ravi Syncfusion Team April 19, 2018 04:11 PM UTC

Hi Stefano, 
 
Thanks for your update. 
 
We have analyzed your query and we suspect that you want to modify the query during the runtime. We suggest you to achieve your requirement in the DataBound event of the Grid.   
Refer the below code snippet  
 
<ej-grid id="FlatGrid" allow-paging="true" allow-filtering="true" databound="bound" row-selecting="select" enable-persistence="true">   
    <e-datamanager url="Home/DataSource" adaptor="UrlAdaptor"></e-datamanager>     
    <e-filter-settings filter-type="Excel" />  
     <e-toolbar-settings show-toolbar="true">  
  
           .        .        .   
  
<script>  
    function bound(args) {          
        setTimeout(ej.proxy(function (args) {  
            $(".e-filtericon").on('click', function () {  
                //add query params  
                var grid = $("#MyGrid").data('ejGrid');  
                grid.option({  
                    query: new ej.Query().addParams('MyParameter', 'MyValue')  
                });  
            });  
        },this),0)  
    }  
  
</script>  
    
 
Refer our help documentation for your reference  
Note: for example we have provided the code snippet for excel filter icon click event. Similarly you can achieve for your requirement.   
 
Regards, 
Nevitha 


Loader.
Up arrow icon