How to return json additional field from controller with datamanager with urladaptor ?

Hi, 
i have a grid with url adaptor that make a  post call to my controller.
the controller have this firm  

 public class DataResult
    {
        public System.Collections.IEnumerable result { get; set; }
        public int count { get; set; }
        public int registered { get; set; } < this is additional field
        public int notregistered { get; set; } < this is additional field
        public int completed { get; set; } < this is additional field
        public int errors { get; set; } < this is additional field
    }


 public virtual ActionResult Datagrid([FromBody]Syncfusion.JavaScript.DataManager dm)
        {
          
            var datatotal =  -> omitted

            DataResult result = new DataResult();
            result.count = datatotal.Count;

            var data = datatotal.Skip(dm.Skip).Take(dm.Take);

            DataOperations operation = new DataOperations();
            if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting 
            {
                data = operation.PerformSorting(data, dm.Sorted);
            }
            if (dm.Search != null && dm.Search.Count > 0)
            {
                data = operation.PerformSearching(data, dm.Search);  //perform search operation in grid. 
            }
            if (dm.Where != null && dm.Where.Count > 0) //Filtering 
            {
                data = operation.PerformWhereFilter(data, dm.Where, dm.Where[0].Operator);
            }
            //int count = data.Cast<MyDocument>().Count();
            //if (dm.Skip != 0)
            //{
            //    data = operation.PerformSkip(data, dm.Skip);
            //}
            //if (dm.Take != 0)
            //{
            //    data = operation.PerformTake(data, dm.Take);
            //}
            result.result = data;

            return Json(result);
        
and return a json with result and count, and it's ok.

Now i need to send to front end other properties, how i can read this ? 

I try to retrieve with oncomplete event, but in args there isn't

<script type="text/javascript">

    function complete(args) {
        if (args.requestType == "save") {
            //Your dialog model to display the message after successful insert and edit actions
        }
    }
</script>

But if i see the returned json from inspect console of my browser i correctly see property.

thank's in advance
Lujs




1 Reply

KM Kuralarasan Muthusamy Syncfusion Team June 2, 2018 03:00 AM UTC

Hi luigi, 

Thanks for contacting Syncfusion support. 

We have analyzed you query and we found that you need to send the additional property to client side. So we suggest you to use customAdaptor of ejDataManager to achieve your requirement. 

Please refer the following code example: 

Client side code: 
 
<ej-grid id="Grid" allow-paging="true" load="load" > 
    <e-datamanager url="/Grid/Data" adaptor="UrlAdaptor" /> 
 
                ... 
 
</ej-grid> 
 
 
<script> 
function load(args){ 
        var customAdaptor = new ej.UrlAdaptor().extend({ 
            processResponse: function (data, ds, query, xhr, request, changes) { 
                alert(data.msg); 
                return data; 
            } 
        }); 
        var gridObj = $("#Grid").ejGrid("instance"); 
        gridObj.model.dataSource.adaptor = new customAdaptor(); 
    }; 
</script> 
 
Controller side: 
 
namespace SyncfusionASPNETCoreApplication2.Controllers 
{ 
    public partial class GridController : Controller 
    { 
         
        public JsonResult Data([FromBody]Test dataObj) 
        { 
 
                            ...             
 
            return Json(new { result = data, count = count, msg="Hi" }); 
        } 
    } 
} 

In this code we have send one additional  property (i.e msg) with result and count in controller side. In client side we have created the customAdaptor by extend the UrlAdaptor and get the msg by using this customAdaptor. We have used grid load event to perform this action. Also we have created the sample with your requirement and that sample can be downloadable from the below link, 


Please refer the following link to know about customAdaptor of ejDataManager: 


Please refer the following link to know about load event of ejGrid: 


Regards, 
Kuralarasan M. 


Loader.
Up arrow icon