jQGrid动态列

前台部门

<select id="xuenian" name="xuenian" class="form-control"></select>
<div class="gridPanel" id="gridPanelZl">
<table id="gridList"></table>
<div id="gridPager"></div>
</div>
<script>
$(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');
}
});
}
</script>
后台部分

public IActionResult Girdhead(int SchoolYearSetID = 1) {
var Girdhead = _dal.JqGridColModel(SchoolYearSetID);
return Json(Girdhead);
}
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);
}
public string JqGridColModel(int SchoolYearSetID) {
IList<SelectModel> selects = GetSchoolYeMoList(SchoolYearSetID);
StringBuilder builder = new StringBuilder();
builder.AppendLine("[");
builder.AppendLine("{ label: '工号', name: '工号', width: 100, align: 'left',frozen: true },");
builder.AppendLine("{ label: '姓名', name: '姓名', width: 80, align: 'left',frozen: true },");
builder.AppendLine("{ label: '部门', name: '部门', width: 100, align: 'left',frozen: true },");
builder.AppendLine("{ label: '教职工类型', name: '教职工类型', width: 80, align: 'left',frozen: true },");
builder.AppendLine("{ label: '行政职务', name: '行政职务', width: 80, 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 builder.ToString();
}

来源:https://www.icode9.com/content-4-847851.html

(0)

相关推荐