1、前台展现单选框datagrid代码
$('#List').datagrid({
url: '@Url.Action("GetList")',
$(window).width() - 10,
methord: 'post',
height: $(window).height() - 35,
fitColumns: true,
sortName: 'Id',
sortOrder: 'desc',
idField: 'Id',
striped: true,//条纹化
rownumbers: true,
singleSelect: false,
selectOnCheck: false,
checkOnSelect: true,
pageSize: 15,
pageList: [15, 20, 30, 40, 50],
pagination: true,
striped: true, //奇偶行是否区分
singleSelect: true,//单选模式
//rownumbers: true,//行号
columns: [[
{field:'ck',checkbox:true},//在datagrid上展现单选框
{ field: 'Id', title: '', 80,hidden:true },
{ field: 'Way', title: '支付方式', 80,sortable:true },
{ field: 'Remark', title: '说明', 80,sortable:true }
]]
});
2、获取所有选中的行的信息
var checkedItems = $('#List').datagrid('getChecked');
var names = [];
$.each(checkedItems, function (index, item) {
names.push(item.Id);
})
3、向后台传输names
if (checkedItems != null) {
$.messager.confirm('提示', '@Suggestion.YouWantToDeleteTheSelectedRecords', function (r) {
if (r) {
$.post("@Url.Action("Delete")?id=" + names, function (data) {
if (data.type == 1)
$("#List").datagrid('load');
$.messageBoxWxc('提示', data.message);
}, "json");
}
});
} else { $.messageBoxWxc('提示', '@Suggestion.PlaseChooseToOperatingRecords'); }
4、后台用string id 接收(注意参数大小写)
string[] Ids = id.Split(',');拆分后即可获取所有选中行的Id