UserRoleColumn.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Bowin.Web.Controls.Mvc;
  7. namespace EMIS.Web.Controls
  8. {
  9. public class UserRoleColumn : DataGridColumn
  10. {
  11. public string FieldName { get; set; }
  12. protected override IDictionary<string, string> GetOptionsList()
  13. {
  14. var baseOptions = base.GetOptionsList();
  15. baseOptions.Add("columnType", "'userRole'");
  16. baseOptions.Add("field", string.Format("'{0}'", string.IsNullOrEmpty(FieldName) ? "emptyField_" + Guid.NewGuid().ToString().Substring(0, 6) : FieldName.Trim()));
  17. baseOptions.Add("formatter", "");
  18. //*****************************************
  19. //Modif : by 劳炳辉 2013.4.26
  20. //修改数据格式化函数,使DataGrid支持多层对象数据[father:[name:"父亲",son:[name:"儿子"]]]的读取
  21. //*****************Start*******************
  22. string val = "value";
  23. if (!string.IsNullOrEmpty(FieldName) && FieldName.IndexOf('.') > -1)
  24. val = "(new Object(row['" + FieldName.Trim().Split('.')[0].Trim() + "']))." + FieldName.Trim().Substring(FieldName.IndexOf('.') + 1).Trim();
  25. #region 增强Formatter参数使用便利性
  26. baseOptions["formatter"] =
  27. "function(value,row,index){ " +
  28. string.Format("return '<a href=\"javascript:EMISFunction.UserRole.Popup('{0}')\">点击查看用户类型</a>'; ",
  29. val) +
  30. "}";
  31. //*****************End*******************
  32. #endregion
  33. //*****************End*******************
  34. return baseOptions;
  35. }
  36. }
  37. }