VmTableItem.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. namespace VberAdmin.Web.Models.Table;
  2. public class VmTableItem
  3. {
  4. public string FiledName { get; set; }
  5. public string DisplayName { get; set; }
  6. public string ClassName { get; set; }
  7. public string Formatter { get; set; }
  8. public string FormatterStr => string.IsNullOrEmpty(Formatter) ? "" : "data-formatter=\"" + Formatter + "\"";
  9. public string Align { get; set; }
  10. public int? Width { get; set; }
  11. public string WidthUnit { get; set; }
  12. public string WidthStr => Width != null ? $" data-width=\"{Width}{WidthUnit}\"" : "";
  13. public bool IsSort { get; set; }
  14. public string Sort => IsSort ? " data-sortable=\"true\"" : "";
  15. protected int TipLength { get; set; }
  16. public string Tip => TipLength > 0 ? $"data-tip=\"{TipLength}\"" : "";
  17. public VmTableItem(string filedName, string displayName, string formatter = "", bool isSort = false, int tipLength = 0)
  18. {
  19. FiledName = filedName;
  20. DisplayName = displayName;
  21. Formatter = formatter;
  22. TipLength = tipLength;
  23. IsSort = isSort;
  24. Align = "center";
  25. }
  26. public VmTableItem WithWidth(int width, string unit = "px")
  27. {
  28. Width = width;
  29. WidthUnit = unit;
  30. return this;
  31. }
  32. /// <summary>
  33. /// 超过指定字符将 被截取 用tip的方式显示
  34. /// </summary>
  35. /// <param name="showLength">默认 30个字符</param>
  36. /// <returns></returns>
  37. public VmTableItem WithTip(int showLength = 30)
  38. {
  39. TipLength = showLength;
  40. return this;
  41. }
  42. public VmTableItem WithSort()
  43. {
  44. IsSort = true;
  45. return this;
  46. }
  47. public VmTableItem WithClassName(string className)
  48. {
  49. ClassName = className;
  50. return this;
  51. }
  52. public VmTableItem WithFormatter(string formatter)
  53. {
  54. Formatter = formatter;
  55. return this;
  56. }
  57. public VmTableItem WithRight()
  58. {
  59. Align = "right";
  60. return this;
  61. }
  62. public VmTableItem WithLeft()
  63. {
  64. Align = "left";
  65. return this;
  66. }
  67. }