如何添加一个行选择列?

本节的 TypeScript 版本有待更新

若要添加列以选择单行或所有行,可以使用 GridRowSelectionMixin。

GridRowSelectionMixin 在 Serenity 1.6.8+ 有效。

示例代码:

  1. public class MyGrid : EntityGrid<MyRow>
  2. {
  3. private GridRowSelectionMixin rowSelection;
  4. public MyGrid(jQueryObject container)
  5. : base(container)
  6. {
  7. rowSelection = new GridRowSelectionMixin(this);
  8. }
  9. protected override List<SlickColumn> GetColumns()
  10. {
  11. var columns = base.GetColumns();
  12. columns.Insert(0, GridRowSelectionMixin.CreateSelectColumn(() => rowSelection));
  13. return columns;
  14. }
  15. protected override List<ToolButton> GetButtons()
  16. {
  17. var buttons = base.GetButtons();
  18. buttons.Add(new ToolButton
  19. {
  20. CssClass = "tag-button",
  21. Title = "Do Something With Selected Rows",
  22. OnClick = delegate
  23. {
  24. var selectedIDs = rowSelection.GetSelectedKeys();
  25. if (selectedIDs.Count == 0)
  26. Q.NotifyWarning("Please select some rows");
  27. else
  28. Q.NotifySuccess("You have selected " + selectedIDs.Count +
  29. " row(s) with ID(s): " + string.Join(", ", selectedIDs));
  30. }
  31. });
  32. return buttons;
  33. }
  34. }