Articles in this section
Category / Section

How to pass additional parameter when using DataManager in grid

1 min read

 

This knowledge base explains the way how to pass additional parameter when using DataManager in grid.

We can have achieved it by using addParams method of ejQuery.

RAZOR

<ej-grid id="FlatGrid" allow-paging="true" action-begin="begin">
    <e-datamanager url="/Home/DataSource" adaptor="UrlAdaptor"/>
    <e-columns>
        <e-column field="OrderID" header-text="Order ID" is-primary-key="true" text-align="Right" width="75"></e-column>
        <e-column field="EmployeeID" header-text="Employee ID" text-align="Right"  width="75"></e-column>
        <e-column field="CustomerID" header-text="Customer ID" text-align="Right" width="75"></e-column>
        <e-column field="Ship City" header-text="Ship City" text-align="Right" width="75"></e-column>
    </e-columns>
</ej-grid>

 

JS

In “action-begin” event of grid we have passed the additional parameter value to the server side (Controller side) using addParams method of ejQuery.

<script type="text/javascript">
    function begin(args) {
           args.model.query.addParams("ID", 10248);
    }
</script>

 

In server side we have inherited and shown the additional parameter value in Syncfusion DataManager class itself.

C#

        public class Test : DataManager       //inherit the class to show age as property of DataManager
        {
            public int ID { get; set; }        
        }

 

C#

Bind the data manager value using the inherited class name “Test”

public IActionResult DataSource([FromBody]Test dm)
        {
           IEnumerable Result = _context.Orders.Take(100).ToList();
            var count = _context.Orders.AsQueryable().Count();
            DataOperations operation = new DataOperations();
            DataResult result = new DataResult();
            if (dm.Skip != 0)
            {
                Result = operation.PerformSkip(Result, dm.Skip);
            }
            if (dm.Take != 0)
            {
                Result = operation.PerformTake(Result, dm.Take);
            }
            result.result = Result;
            result.count = count;
            return Json(result)
        }
    public class DataResult
        {
             public IEnumerable result { get; set; }
            public int count { get; set; }
        }

 

C:\Users\Manisankar.durai\Desktop\sshot-1.png

Figure 1: Additional parameter in DataManager class

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment