贴上代码:
1 ………… 2 3 @(Html.DevExtreme().DataGrid<Model>() 4 ………… 5 .KeyExpr("Id") 6 7 .Selection(s => 8 9 s.Mode(SelectionMode.Multiple) //开启多选 10 .ShowCheckBoxesMode(GridSelectionShowCheckBoxesMode.Always) //页面上总是显示复选框 11 .SelectAllMode(SelectAllMode.Page) //全选时,一次选择一页 12 ) 13 ………… 14 .OnToolbarPreparing("toolbar_preparing") //制定工具栏 15 .OnSelectionChanged("selectionChanged") //勾选事件 16 ) 17 18 <script> 19 20 var selectedIds;// 选中记录的主键值(key) 21 //勾选事件 22 function selectionChanged(e) { 23 selectedIds = e.selectedRowKeys; 24 } 25 26 //制定工具栏 27 function toolbar_preparing(e) { 28 e.toolbarOptions.items.unshift( 29 { 30 location: "before", 31 template: "<span>总数:10</span>" 32 }, 33 { 34 location: "after", 35 widget: "dxButton", 36 options: { 37 text: "搜索", 38 icon: "find", 39 type:"ButtonType.Default", 40 onClick: function () { 41 //点击事件, 获取到selectedIds 进行业务处理 42 } 43 } 44 }); 45 46 } 47 </script>