We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Error when updating Grid Data source using external filter from Pages other than first

Thread ID:

Created:

Updated:

Platform:

Replies:

128418 Jan 20,2017 02:23 AM Jan 24,2017 11:14 PM ASP.NET Web Forms 8
loading
Tags: Grid
Vishal Gupta
Asked On January 20, 2017 02:23 AM

I have implemented an asp.net ejGrid and populated Paging and the Data from WebMethod Adapter, as my Data is there is sqlserver database and there are more than 10K records.
When I move to some other Page say Page 3, and then Search an item existing on Page1, then I get below error in console :--

Uncaught TypeError: Cannot read property 'items' of undefined
    at Object._initColumns (ej.web.all.min.js:10)
    at Object.addInitTemplate (ej.web.all.min.js:10)
    at Object._initGridRender (ej.web.all.min.js:10)
    at Object.<anonymous> (ej.web.all.min.js:10)
    at t.DataManager.<anonymous> (ScriptResource.axd:10)
    at j (jquery-2.1.4.min.js:2)
    at Object.fireWith [as resolveWith] (jquery-2.1.4.min.js:2)
    at t.DataManager.<anonymous> (ScriptResource.axd:10)
    at t.DataManager.<anonymous> (ScriptResource.axd:10)
    at Object.success (ScriptResource.axd:10)

The Error Screenshot is attached..
Sample Code is also Attached.

 Also the Page Transition between pages is Slow.. Kindly help to guide the correct way of doing this.


Attachment: Error_5ec9c1b0.rar

Vishal Gupta
Replied On January 20, 2017 02:25 AM

Same code is attached here.

Attachment: SampleApp_ae4046ad.rar

Saravanan Arunachalam [Syncfusion]
Replied On January 23, 2017 04:28 AM

Hi Gupta, 
Thanks for contacting Syncfusion’s Support. 
It could be possibly occur due to return the improper formatted data from the server while searching. So, please ensure the returned data from the server as properly formatted (result and count). 
If you still faced the issue, please provide the following details. 
1.       Share the response header while searching like below image 
 
2.       Share the request format from the Network tab. 
Regards, 
Saravanan A. 


Vishal Gupta
Replied On January 23, 2017 06:17 AM

Hi Saravanan,

Thanks for reply, Please find below the request format.

The Response Header is also attached.

    1. Request URL:
      http://localhost:52454/default.aspx/GridData?userId=
    2. Request Method:
      POST
    3. Status Code:
      200 OK
    4. Remote Address:
      [::1]:52454
  1. Response Headersview source
    1. Cache-Control:
      private, max-age=0
    2. Content-Length:
      1688
    3. Content-Type:
      application/json; charset=utf-8
    4. Date:
      Mon, 23 Jan 2017 11:09:48 GMT
    5. Server:
      Microsoft-IIS/8.0
    6. X-Powered-By:
      ASP.NET
    7. X-SourceFiles:
      =?UTF-8?B?QzpcVXNlcnNcTVRTTUdNVFxEb2N1bWVudHNcVmlzdWFsIFN0dWRpbyAyMDEzXFByb2plY3RzXFNhbXBsZUFwcFxTYW1wbGVBcHBcZGVmYXVsdC5hc3B4XEdyaWREYXRh?=
  2. Request Headersview source
    1. Accept:
      application/json, text/javascript, */*; q=0.01
    2. Accept-Encoding:
      gzip, deflate, br
    3. Accept-Language:
      en-US,en;q=0.8
    4. Connection:
      keep-alive
    5. Content-Length:
      76
    6. Content-Type:
      application/json; charset=UTF-8
    7. Cookie:
      ASP.NET_SessionId=zwm003qw2ydvqtojgnycvqmx
    8. Host:
      localhost:52454
    9. Origin:
      http://localhost:52454
    10. Referer:
      http://localhost:52454/Default.aspx
    11. User-Agent:
      Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
    12. X-Requested-With:
      XMLHttpRequest
  3. Query String Parametersview sourceview URL encoded
    1. userId:
  4. Request Payloadview source
      1. {value: {requiresCounts: true, params: {}, skip: 0, take: 10}, params: {}}
        1. params:{}
        2. value:{requiresCounts: true, params: {}, skip: 0, take: 10}



Attachment: response_header_7a8d51bc.rar

Vishal Gupta
Replied On January 23, 2017 07:37 AM

HI Team,

The actual issue is as below :--

I have asp.net ejgrid  having 10 pages and an external filter to select specific records. when I give values in the filter then dynamic sql is created and fresh data is extracted from database in the URL Adapter method show below. In this case, suppose only 3 records are fetched, now the values of skip and take should adjust automatically with the Data Source , but they are still comming as 40 and 10, due to which NO data is actually comming in result and error is comming.

Below is my web method, the GetUserRecords  function fetches value from database from dynamic sql created as per the external filter applied, and provide data back in dataTable.

  [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public static object GridData(int skip, int take)
        {
            DataTable data = GetUserRecords();

            var sRec = (from DataRow row in data.Rows
                        select new UserTable
                        {
                            SeqNo = Convert.ToInt32(row["SeqN"].ToString()),
                            UserId = row["UserID"].ToString(),
                            Password = row["Password"].ToString(),
                            Priviledge = Convert.ToInt32(row["Priviledge"].ToString()),
                            Email = row["Email"].ToString(),
                            CompanyName = row["CompanyName"].ToString(),
                            CompanyId = Convert.ToInt32(row["CompanyId"].ToString()),
                            Comments = row["Comments"].ToString()
                        }).ToList();

            var res = sRec.Skip(skip).Take(take).ToList(); 

            return new { result = res, count = sRec.Count };

        }


In above function, If I am at Page 5 of the Grid and then I apply the external Filter,  It may result in a data table of 3 rows, but the Skip and Take above still have value as 40 and 10 
( as I have implemented paging with 10 records only in one page)

Kindly check and revert.

Saravanan Arunachalam [Syncfusion]
Replied On January 24, 2017 07:57 AM

Hi Vishal, 
The cause of the issue is you have filtered the data externally with current page values (Skip and Take). So, we suggest you to filter the data with default pageSettings value. Please refer to the below code example. 
[Aspx.cs] 
protected void cmdSearch_Click(object sender, EventArgs e) 
        { 
            sFilter = textSearchUserID.Text; 
            this.Grid1.DataManager = new DataSource(); 
            this.Grid1.DataManager.URL = "GridFeatures.aspx/GetData"; 
            this.Grid1.DataManager.Adaptor = "WebMethodAdaptor"; 
            this.Grid1.PageSettings = new PageSettings(); 
            this.Grid1.DataBind(); 
        } 
 
Regards, 
Saravanan A. 


Vishal Gupta
Replied On January 24, 2017 11:48 AM

Thanks a  Lot saravanan, your suggestion worked like a charm.

Please guide me for another issue that "transition between pages in the grid is slow", this is because every time, I select a page, the DataManager URL GetData  is called and it again gets the complete records from database by firing the sql (select * from table) and then extract 10 records are per skip and take values.

Is there any better way to load the entire records once in some array or collection and then show records from this collection on page change, thereby avoiding database hit every time.  Please suggest.

Vishal Gupta
Replied On January 24, 2017 12:27 PM

HI saravanan,

I have been able to store the values in a List collection and avoid database fetch on paging.,

my ALL issues stands closed now.

Thanks a lot for your help. You Rock !!

Saravanan Arunachalam [Syncfusion]
Replied On January 24, 2017 11:14 PM

Hi Vishal,  
Thanks for your update.            
We are happy that the provided information helped you. 
Regards, 
Saravanan A. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;