Rebind grid after it was loaded with custom adaptor

Hi, 
on page load i correnctly bind the datasource on grid with custom adaptor, and it's ok.
Now i need to make a fulltext search and i have a textbox with button that call an action of a controller, made with ajax call.
I need to return the new datasource and update (rebind) the datasource of the grid object.

Below the code

 public class DataResult
    {
        public System.Collections.IEnumerable result { get; set; }
        public int count { get; set; }
        public int totalRegistered { get; set; }
        public int totalNotRegistered { get; set; }
        public int totalStandby { get; set; }
        public int totalDeleted { get; set; }
    }

//called by ajax
  public virtual async Task<JsonResult> LoadFullText(string texttosearch)
        {
            string view = string.Empty;
            string msg = string.Empty;
            int docType = (int)GetDocumentType();
            int TotalRegistered = 0, TotalNotRegistered = 0, TotalStandby = 0, TotalDeleted = 0, Total = 0;
            try
            {
                var list = _dataDataService.GetDocumentsListFullText(texttosearch)
                DataResult result = new DataResult();
                result.count = list.Count;

                result.result = list;

                return Json(result);
          }
catch(Exception ex)
{
throw ex;
}
}

//this is js that are triggered on search button (with arrow)

   $("body").on('click', "a.fulltext", function (e) {
            e.preventDefault();
            e.stopPropagation();
            url = $(this).attr("rel='nofollow' href");
            fulltext = $(this).data("fulltext");
            if (fulltext) {
                //ricarico la parte di view con la grid
                var text = $("#texttosearch").val();
                if (text.length > 0) {
                    $("#rowLoading").show();
                    $("#gridload").hide();
                    $.getJSON(url, { texttosearch: text }, function (data) {
                        if (data.count>0) {
                   
                            var gridData = ej.parseJSON(data.result);
                            var gridModel = $("#FlatGrid").ejGrid("instance");
                          
                            //gridObj.model.dataSource.adaptor = new customAdaptor();
                            gridModel.dataSource = ej.DataManager({
                                json: data.result
                            });
                            
                        }
                        else {
                            error(data.data);
                        }

                    }).fail(function () {
                        error("An Issue is occurred");
                    }).then(function () {
                        $("#rowLoading").hide();
                        $("#gridload").fadeIn("slow", function () {

                        });
                    });
                } else {
                    error('No text to search');
                }

Any help would be really appreciated.

Luigi


1 Reply

SE Sathyanarayanamoorthy Eswararao Syncfusion Team June 14, 2018 12:44 PM UTC

Hi Luigi, 

Thanks for contacting Syncfusion support. 

According to your query we suspect that you need to bind the new dataSource to the Grid which is returned from an ajax call. To achieve this requirement we suggest you to use the dataSource method of Grid. 

Please refer the below code example. 
  
$("body").on('click', "a.fulltext", function (e) { 
            e.preventDefault(); 
            e.stopPropagation(); 
            url = $(this).attr("rel='nofollow' href"); 
            fulltext = $(this).data("fulltext"); 
            if (fulltext) { 
                //ricarico la parte di view con la grid 
                var text = $("#texttosearch").val(); 
                if (text.length > 0) { 
                    $("#rowLoading").show(); 
                    $("#gridload").hide(); 
                    $.getJSON(url, { texttosearch: text }, function (data) { 
                        if (data.count>0) { 
                    
                            var gridData = ej.parseJSON(data.result); 
                            var gridModel = $("#FlatGrid").ejGrid("instance"); 
                           
                            gridModel.dataSource(gridData); 
                             
                        } 
                        else { 
                            error(data.data); 
                        } 
 
                    }).fail(function () { 
                        error("An Issue is occurred"); 
                    }).then(function () { 
                        $("#rowLoading").hide(); 
                        $("#gridload").fadeIn("slow", function () { 
 
                        }); 
                    }); 
                } else { 
                    error('No text to search'); 
                } 
 

Please refer the below documentation for details of dataSource method. 


If you need any further assistance please get back to us. 

Regards,
Sathyanarayanamoorthy 


Loader.
Up arrow icon