Hi Dan,
Thanks for using Syncfusion Products.
We regret to let you know that we are unable to reproduce
the issue in our end. Based on your requirement we have created a simple sample
with the video demonstration of working sample and the same can be downloaded
from below link.
Sample: http://www.syncfusion.com/downloads/support/directtrac/130427/EJGrid-1161763710.zip
Video: http://www.syncfusion.com/downloads/support/directtrac/130427/datasource-1390367644.zip
Could you please replicate the issue in the above sample and
send us back or send us more information about the issue so that we could sort
out the cause of the issue and provide you a response as early as possible?
Regards,
Alan Sangeeth S
Hi Dan
Sorry for the inconvenience caused.
We have analyzed your issue and we have modified the sample based on your requirement and the same can be downloaded from the below link
Sample Link: http://www.syncfusion.com/downloads/support/directtrac/general/EJGrid_3521f1c71942730838.zip
For your kind information , for refreshing the grid datasource in ajax success it is necessary to return the json data from the server. So please refer the below code snippet for passing the JsonResult from the server to client.
public JsonResult Post() { try { IHubContext hub = GlobalHost.ConnectionManager.GetHubContext("MainHub"); //the above line is not necessary because we have passed the json data to the client var data = Data(); return new JsonResult() { Data = data, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } |
function callSignalR() { $.ajax({ url: "api/SignalRTest", contenttype: "application/json", dataType: "json", type: "POST", success: function (e) { flag=0; $("#Grid").ejGrid("dataSource", e.Data); } }); } |
And also we have added the user defined function “RefreshData” in the MainHub.cs file. Using ActionComplete event of the grid we have refreshed the data in client from the server.
Please refer the below code snippet
MainHub.cs
public class MainHub : Microsoft.AspNet.SignalR.Hub { . . . . . . . . public void RefreshData(object datamanager) { Clients.Others.refreshData(datamanager); } }
test.js
$(function () { window.testHub = $.connection.mainHub; // Client method window.testHub.client.refreshData = function (dataModel) { flag = 1; $("#Grid").ejGrid("dataSource", dataModel); }; // Start the connection. $.connection.hub.start() .done(function () {
window.actionComplete = function (args) { if (flag == 0) { if (args.requestType == "refresh") {
window.testHub.server.refreshData(args.model.dataSource);
} } }
}) .fail(function () { }); }); |
Please try the above sample and let us know if you have any queries.
Regards,
Gowthami V.
Hi Dan,
We are able to reproduce the issue in our end and the cause of the issue is we had bound Grid datasource array to the object type parameter of “RefreshData” method in MainHub.cs file in which it returns data as object of object arrays. So as you have mentioned we need to stringify the data before passing it to the hub and then we need to convert the stringified array to json object using parseJSON before passing it to Grid “dataSource” method. Please refer the following code snippets.
window.testHub.client.refreshData = function (dataModel) { flag = 1; $("#Grid").ejGrid("dataSource", $.parseJSON(dataModel)); };
window.actionComplete = function (args) { if (flag == 0) { if (args.requestType == "refresh") window.testHub.server.refreshData(JSON.stringify(args.model.dataSource)); } }
public void RefreshData(string datamanager) { Clients.Others.refreshData(datamanager); } |
Please let us know if you have any queries.
Regards,
Alan Sangeeth S
Hi Dan,
Thanks for the update.
We have modified the sample based on your requirement and the same can be downloaded from below link.
Sample: http://www.syncfusion.com/downloads/support/directtrac/130698/EJGrid_3521f1c7409359564.zip
In the above sample, instead of passing string value to the server-side, we have used List of Strongly typed Class as argument in SignalR server call and returned serialized data. Please refer the following code snippets.
public void RefreshData(List<EditableOrder> datamanager) { var serializedData = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(datamanager); Clients.Others.refreshData(serializedData); }
window.testHub.client.refreshData = function (dataModel) { flag = 1; $("#Grid").ejGrid("dataSource", $.parseJSON(dataModel)); }; |
Please let us know if you have any queries.
Regards,
Alan Sangeeth S