First, define an entity class
- public class DataGridModel
- {
- public string field { get; set; }
- public string title { get; set; }
- public int width { get; set; }
- }
Copy code
Then, the dynamically bound data list needs to be added in a loopDataGridModel plus attributes:
- var dgList = new List<DataGridModel>();
- list.ForEach(x =>
- {
- dgList.Add(new DataGridModel
- {
- field = x.name,
- title = x.bewrite,
- width = 100
- });
- });
Copy code
Finally, the foreground ajax sends a post request and dynamically binds the columns:
- var Extcredits = $("#Extcredits").val();
- var id = $("#id").val();
- $.post("/Home/JsonDictionarys", "id=" + Extcredits, function (data) {
- var arr = [];
- arr.push(data.Data);
- $('#dg').datagrid({
- url: '/BoardRoom/GetJoinBoardRoomUser/',
- type: "post",
- rownumbers: true,
- pagination:true,
- queryParams: {
- id: id
- },
- fitColumns: true,
- singleSelect: true,
- columns: arr
- });
- });
Copy code
|