This article is a mirror article of machine translation, please click here to jump to the original article.

View: 17243|Reply: 5

[EasyUI] EasyUI datagrid tables dynamically bind field columns

[Copy link]
Posted on 10/29/2015 10:22:42 AM | | |
First, define an entity class
  1. public class DataGridModel
  2.     {
  3.         public string field { get; set; }
  4.         public string title { get; set; }
  5.         public int width { get; set; }
  6.     }
Copy code


Then, the dynamically bound data list needs to be added in a loopDataGridModel plus attributes:


  1. var dgList = new List<DataGridModel>();
  2.             list.ForEach(x =>
  3.             {
  4.                 dgList.Add(new DataGridModel
  5.                 {
  6.                     field = x.name,
  7.                     title = x.bewrite,
  8.                     width = 100
  9.                 });
  10.             });
Copy code


Finally, the foreground ajax sends a post request and dynamically binds the columns:

  1. var Extcredits = $("#Extcredits").val();
  2.             var id = $("#id").val();
  3.             $.post("/Home/JsonDictionarys", "id=" + Extcredits, function (data) {
  4.                 var arr = [];
  5.                 arr.push(data.Data);
  6.                 $('#dg').datagrid({
  7.                     url: '/BoardRoom/GetJoinBoardRoomUser/',
  8.                     type: "post",
  9.                     rownumbers: true,
  10.                     pagination:true,
  11.                     queryParams: {
  12.                         id: id
  13.                     },
  14.                     fitColumns: true,
  15.                     singleSelect: true,
  16.                     columns: arr
  17.                 });
  18.             });
Copy code






Previous:JQuery EasyUI DataGrid refreshes data content regularly
Next:Translate all the field names of the DataTable into Chinese and return
Posted on 10/29/2015 10:57:55 AM |
Did you pass the interview?
 Landlord| Posted on 10/29/2015 12:53:35 PM |
Summer Posted on 2015-10-29 10:57
Did you pass the interview?

Passed now working at the company   
Posted on 10/29/2015 1:33:58 PM |
Summer Posted on 2015-10-29 10:57
Did you pass the interview?

I also passed
Posted on 10/29/2015 2:16:36 PM |
Xiao Zhao posted on 2015-10-29 12:53
Passed now working at the company

Good
Posted on 10/29/2015 2:16:47 PM |
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com