I’m currently encountering an issue when trying to render data in the Flexmonster grid. The report loads successfully only when the API response size is below 500 MB.
However, if the response exceeds 500 MB, the AJAX call enters the error handler. Interestingly, the response status code is 200 (OK), but the responseText
is empty (""
). As a result, the data is not rendered, and users are unable to see the report on the UI.
Could you please guide me on how to handle large API responses and ensure that the data can be successfully rendered in the Flexmonster grid?
I’ve included all relevant code for your reference below:
-------------------------------------------------------
API Code As belows:
[HttpPost] public CallResponse ZFilterResult([FromBody] ZFilter filter) { CommonProperties commonProperties = CommonMethods.GetCommonProperties(User); filter.UserId = commonProperties.LoginId; filter.UserCode = commonProperties.UserName; CallResponse callResponse = _service.ZFilterResult(filter); try { string responseJson = Newtonsoft.Json.JsonConvert.SerializeObject(callResponse); long responseSizeInBytes = System.Text.Encoding.UTF8.GetByteCount(responseJson); double responseSizeInMB = responseSizeInBytes / (1024.0 * 1024.0); } catch (Exception ex) { } return callResponse; }
---------------------------------------------------------------------------------
Services Code As belows:
public CallResponse ZFilterResult(ZSHIPFilter filter) { CallResponse callResponse = new CallResponse(); DateTime dtSOne = DateTime.Now; try { using (var context = new DBOrgEntities()) { var prmCustomerCode = (string.IsNullOrEmpty(filter.CustomerCode) ? "NULL" : "'" + filter.CustomerCode + "'"); var prmSalesNo = (string.IsNullOrEmpty(filter.SalesNo) ? "NULL" : "'" + filter.SalesNo + "'"); var prmMaterial = (string.IsNullOrEmpty(filter.Material) ? "NULL" : "'" + filter.Material + "'"); var prmSalesOffice = (string.IsNullOrEmpty(filter.SalesOffice) ? "NULL" : "'" + filter.SalesOffice + "'"); var prmSalesGroup = (string.IsNullOrEmpty(filter.SalesGroup) ? "NULL" : "'" + filter.SalesGroup + "'"); var prmSalesOrganization = (string.IsNullOrEmpty(filter.SalesOrganization) ? "NULL" : "'" + filter.SalesOrganization + "'"); string strQuery = string.Format(@"Exec [dbo].[USP_ZFilterReport] @CustomerCode = {0}, @SalesNo = {1}, @Material = {2}, @SalesOffice = {3}, @SalesGroup = {4}, @SalesOrg = {5}", prmCustomerCode, prmSalesNo, prmMaterial, prmSalesOffice, prmSalesGroup, prmSalesOrganization); DataSet ds = GetDataSetResultNonSingleton("Provider=SQLOLEDB;" + ConnectionString, strQuery); StringBuilder stringBuilder = new StringBuilder(); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 50000) { stringBuilder = new StringBuilder(0, int.MaxValue); } string JSONresult = JsonConvert.SerializeObject(ds, Formatting.Indented); stringBuilder.Append(JSONresult); callResponse.TotalRowsCount = (ds != null && ds.Tables.Count > 0) ? ds.Tables[0].Rows.Count : 0; callResponse.Data = stringBuilder.ToString(); callResponse.Status = true; callResponse.Message = MessageResource.GetString("Success"); } } catch (Exception ex) { logger.Error(ex); callResponse.Status = false; callResponse.Message = "Error :" + ex.Message; } finally { GC.Collect(); } TimeSpan ts = DateTime.Now - dtSOne; callResponse.ProcessingTimeInSeconds = ts.TotalSeconds; return callResponse; }
-----------------------------------
CallResponse Class definition as belows:
public class CallResponse { ////// Parameter less constructor /// public CallResponse() { Status = false; Message = string.Empty; Data = new object(); ErrorList = new List(); TotalRowsCount = 0; ProcessingTimeInSeconds = 0; } /// /// Parameterize constructor /// public CallResponse(bool status, string message, object data, ListerrorList) { Status = status; Message = message; Data = data; ErrorList = errorList; TotalRowsCount = 0; ProcessingTimeInSeconds = 0; } /// /// Message Attribute /// [JsonProperty("Message")] public string Message { get; set; } ////// Status Attribute /// [JsonProperty("Status")] public bool Status { get; set; } ////// Data Attribute /// [JsonProperty("Data")] public object Data { get; set; } ////// Processing Time In Seconds Attribute /// [JsonProperty("ProcessingTimeInSeconds")] public double ProcessingTimeInSeconds { get; set; } ////// Total Rows Count Attribute /// [JsonProperty("TotalRowsCount")] public decimal TotalRowsCount { get; set; } private List_errorList; /// /// ErrorList Attribute /// [JsonProperty("ErrorList")] public ListErrorList { get { if (_errorList == null) { _errorList = new List (); } return _errorList; } set { _errorList = value; } } }
---------------------------------------------------
AJAX Call code as belows:
$.ajax({ url: gSuperUrl + 'ZReport/ZFilterResult', type: 'POST', dataType: 'json', data: jsonFilter, success: function (data) { if (data.Status == true) { var rptResult = JSON.parse(data.Data); ZSHIPResult = rptResult.Table; BindFlexmonster(ZSHIPResult); } }, error: function (error) { LogJSErrorsDetails(window.location.pathname.split("/").pop(), arguments.callee.name, eval(error)); } });
Hello, Nagaraj!
Thank you for reaching out to us.
The issue with AJAX failing on large responses (over 500 MB) is unrelated to Flexmonster, but likely occurs due to browser or server limits when handling large JSON strings. The JSON dataset is serialized into a string in the provided code, which can hit the string size limit in JavaScript or C#.
For working with large JSON datasets, we recommend using Flexmonster's built-in functionality to fetch remote JSON data using the filename
parameter. Our component is optimized for efficient data loading, and using the built-in functionality would provide additional benefits, such as displaying the data loading status with Flexmonster UI, better synchronization with events, and improving the report saving experience by only storing the URL inside the report. The filter parameters can be passed to your server within the filename
property by using the request parameters, as shown in this code snippet:
dataSource: {
type: "json",
filename: "data/retail-data.json?contry=USA"
}
Additionally, we recommend the following optimizations when working with large files:
useStreamLoader
property to optimize the loading by using a stream loader.Please let us know if our recommendations helped you.
Best Regards,
Maksym