Workaround for the DataGrid empty DataSet not refreshed in Easyui

Source: Internet
Author: User

The DataGrid space can request JSON data asynchronously and overwrite the new data with the original data and redraw the data table.

But when it comes back to the empty data set, JS generates an error like this:

NULL  for (var i=0;i<rows.length;i++) {                    ^

What is the problem?

The content returned when you can see the empty data set is:

{"Total": "0", "Rows":null}

Note that the value for rows is null, and a collection is required to ensure that JS is not faulted, that is, the empty set [].

Workaround:

If you ignore the JS error, only need to render the correct results on the page, you can refresh the data set, manually clear the data, so that the timely return of NULL causes JS error stop, the page renders an empty dataset is also correct.

$ (' #grid '). DataGrid (' LoadData ', {total:0, rows: []});  

If it is elegant, let the backend (for example, PHP) return the empty set is not NULL, but [], the same can solve the problem:

if ($result[' Total ']==0) {  echo ' {"All": "0", "Rows": []} ';   return  ;}

Or

if ($result[' rows ']===null)   $result=array(); echo json_encode ($result);

Workaround for the DataGrid empty DataSet not refreshed in Easyui

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.