How to pass additional parameter when using DataManager in grid

Hello,

Sorry but I don't understand how to pass parameter like : https://www.syncfusion.com/kb/7863/how-to-pass-additional-parameter-when-using-datamanager-in-grid
Have you sample for Asp.net Core EJS 2?

3 Replies

RN Rahul Narayanasamy Syncfusion Team June 28, 2018 01:38 PM UTC

Hi TheDarkBoz, 
 
You can pass additional parameters to server by using addParams method of Query class. Please find the below documentation link for your reference. 
 
 
If you are still facing difficulties in this, please get back to us for further assistance. 
 
Regards, 
Rahul Narayanasamy. 



AG Anand Gupta August 22, 2019 02:03 AM UTC

Hi, 
On some action on grid (eg. delete) we are refreshing the grid data. But how can we updated the extra params of query class.


TS Thavasianand Sankaranarayanan Syncfusion Team August 22, 2019 08:51 AM UTC

Hi Anand, 

We can achieve your requirement by extending the UrlAdapator and we need to pass the additional parameter to the controller CRUD model class by using custom adaptor. 

Refer the below code example. 

[index.cshtml] 

<div class="col-lg-12 control-section"> 
 
    <ejs-grid id="Grid" allowPaging="true" created="created" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })"> 
            <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true"></e-grid-editSettings> 
       <e-grid-columns> 
            <e-grid-column field="orderID" isPrimaryKey="true" headerText="Order ID" textAlign="Right" width="100"></e-grid-column> 
            <e-grid-column field="customerID" headerText="Customer ID" type="string" width="120"></e-grid-column> 
            <e-grid-column field="freight" headerText="Freight" textAlign="Right" format="C2" editType="numericedit" width="120"></e-grid-column> 
            <e-grid-column field="shipCountry" headerText="Ship Country" width="150"></e-grid-column> 
        </e-grid-columns> 
    </ejs-grid> 
</div> 
 
<script type="text/javascript"> 
 
    function created() { 
 
       // sending additional parameter here 
        class SerialNoAdaptor extends ej.data.UrlAdaptor { 
            beforeSend(dataManager, request, ajaxSettings) { 
                 
                var action = JSON.parse(ajaxSettings.data).action; 
                if (action == 'remove') { 
                    var dataStrng = ajaxSettings.data; 
                    dataStrng = dataStrng.slice(0, -1); 
                    dataStrng = dataStrng + ',"Params":' + 1 + '}'; 
                    ajaxSettings.data = dataStrng; 
                    ajaxSettings.options.data = dataStrng; 
                } 
            } 
        } 
        var grid = document.querySelector('#Grid').ej2_instances[0]; 
        grid.dataSource = new ej.data.DataManager({ 
            url: "/Home/UrlDataSource", 
            insertUrl: "/Home/Insert", 
            updateUrl: "/Home/Update", 
            removeUrl:"/Home/Delete",  
            adaptor: new SerialNoAdaptor() 
        });      
       
    } 
     
     
</script> 
------------------------------------------------------------------------------------------------------------- 
[HomeContrller.cs] 

public ActionResult Delete([FromBody]CRUDModel<OrdersDetails> value) 
        { 
            if (value.Params == 1) 
            { 
                OrdersDetails.GetAllRecords().Remove(OrdersDetails.GetAllRecords().Where(or => or.OrderID == int.Parse(value.key.ToString())).FirstOrDefault()); 
 
            } 
            return Json(value); 
        } 
 
 
public class CRUDModel<T> where T : class 
        { 
            public string action { get; set; } 
 
            public string table { get; set; } 
 
            public string keyColumn { get; set; } 
 
            public object key { get; set; } 
 
            public T value { get; set; } 
 
            public List<T> added { get; set; } 
 
            public List<T> changed { get; set; } 
 
            public List<T> deleted { get; set; } 
 
            public int Params { get; set; } 
        } 


We have prepared a sample and it can be downloadable from the below location. 

  
Regards, 
Thavasianand S. 


Loader.
Up arrow icon