Go to my github

jqGrid--动态列

前台部门

<select id="xuenian" name="xuenian" class="form-control"></select>
<div class="gridPanel" id="gridPanelZl">
<table id="gridList"></table>
<div id="gridPager"></div>
</div>

javascript

$(function () {
//select2下拉
$("#xuenian").bindSelect({
url: pageUrl + "SchoolYearSelectJson"
});
$("#xuenian").on("change", function (e) {
ininGrid();
}); 
ininGrid();
});
function ininGrid() {
SchoolYearSetID = $("#xuenian").val();
$.ajax({
url: pageUrl + "Girdhead",
data: { SchoolYearSetID: SchoolYearSetID },
type: "post",
dataType: "json",
async: false,
success: function (restdata) {
$.jgrid.gridUnload("gridList");
$("#gridList").dataGrid({
url: pageUrl + "GetGridJson",
postData: { SchoolYearSetID: SchoolYearSetID, keyword: keyword },
datatype: "json",
mtype: 'POST',
async: false,
height: $(window).height() - 220,
colModel: eval(restdata),
rowNum: 20,
rowList: [20, 50, 100],
pager: '#gridPager',//翻页的导航栏
sortname: '部门',//默认的排序列,会被提交到后台
viewrecords: true,//总记录条数
sortorder: "asc",//选择排序方式 降序或升序(asc or desc)
});
$("#gridList").jqGrid('setGridParam', {
url: pageUrl + "GetGridJson",
postData: { SchoolYearSetID: SchoolYearSetID, keyword: keyword },

}).trigger('reloadGrid');
}
});
}

后台部分

public IActionResult Girdhead(int SchoolYearSetID = 1) {
IList<SelectModel> selects = GetSchoolYeMoList(SchoolYearSetID);
StringBuilder builder = new StringBuilder();
builder.AppendLine("[");
builder.AppendLine("{ label: '工号', name: '工号', width: 100, align: 'left',frozen: true },");

foreach(var item in selects) {
  builder.AppendLine("{label:'" + item.text + "', name: '" + item.text + "', width: 60, align: 'center',formatter: function (cellvalue) {return Math.round(cellvalue);}}, ");
}

builder.AppendLine("{label:'总课时', name: '总课时', width: 60, align: 'center',formatter: function (cellvalue) {return Math.round(cellvalue);}}, ");
builder.AppendLine("{label:'课时费', name: '课时费', width: 60, align: 'center',formatter: function (cellvalue) {return Math.round(cellvalue);}}, ");

builder.AppendLine("]");
 return Json(builder.ToString()); 

}
public IActionResult GetGridJson(int SchoolYearSetID,string sidx = "a.部门",string sord = "asc",int page = 1,int rows = 15) 
{

  var table = _dal.JqGridData(SchoolYearSetID,keyword,branch,sidx,sord,page,rows);

  return Content(table);
}

 

posted @ 2021-02-06 08:55  峡谷少爷  阅读(445)  评论(0编辑  收藏  举报