列的使用


InfoPanel内置了很多对于列的操作方法,可以通过这些方法很灵活的操作列数据。

设置列宽

  1. info.AddField("Name", "name", db.Varchar).FieldWidth(100)

默认隐藏列

  1. info.AddField("Name", "name", db.Varchar).FieldHide()

设置为可排序

  1. info.AddField("Name", "name", db.Varchar).FieldSortable()

设置为固定

  1. info.AddField("Name", "name", db.Varchar).FieldFixed()

设置为可筛选

  1. info.AddField("Name", "name", db.Varchar).FieldFilterable()

设置筛选的操作符与操作表单类型:

  1. // 设置操作符为like,模糊查询
  2. info.AddField("Name", "name", db.Varchar).FieldFilterable(types.FilterType{Operator: types.FilterOperatorLike})
  3. // 设置为单选类型
  4. info.AddField("Gender", "gender", db.Tinyint).
  5. FieldFilterable(types.FilterType{FormType: form.SelectSingle}).
  6. FieldFilterOptions([]map[string]string{
  7. {"value": "0", "field": "men"},
  8. {"value": "1", "field": "women"},
  9. }).FieldFilterOptionExt(map[string]interface{}{"allowClear": true})
  10. // 设置为时间范围类型,范围查询
  11. info.AddField("CreatedAt", "created_at", db.Timestamp).FieldFilterable(types.FilterType{FormType: form.DatetimeRange})

帮助方法

字符串操作

限制输出长度

  1. info.AddField("Name", "name", db.Varchar).FieldLimit(10)

首字母大写

  1. info.AddField("Name", "name", db.Varchar).FieldToTitle()

去除空格

  1. info.AddField("Name", "name", db.Varchar).FieldTrimSpace()

字符串截取

  1. info.AddField("Name", "name", db.Varchar).FieldSubstr(0, 3)

字符串转大写

  1. info.AddField("Name", "name", db.Varchar).FieldToUpper()

字符串转小写

  1. info.AddField("Name", "name", db.Varchar).FieldToLower()

如果想要全局进行过滤操作

那么可以调用插件的方法:

  1. adminPlugin := admin.NewAdmin(...)
  2. // 限制输出
  3. adminPlugin.AddDisplayFilterLimit(limit int)
  4. // 去除空格
  5. adminPlugin.AddDisplayFilterTrimSpace()
  6. // 截取字符串
  7. adminPlugin.AddDisplayFilterSubstr(start int, end int)
  8. // 首字母大写
  9. adminPlugin.AddDisplayFilterToTitle()
  10. // 大写
  11. adminPlugin.AddDisplayFilterToUpper()
  12. // 小写
  13. adminPlugin.AddDisplayFilterToLower()
  14. // xss过滤
  15. adminPlugin.AddDisplayFilterXssFilter()
  16. // js过滤
  17. adminPlugin.AddDisplayFilterXssJsFilter()

如果想要在表格或表单显示层面进行过滤操作

  1. info := table.NewDefaultTable(...).GetInfo()
  2. info.AddLimitFilter(limit int)
  3. info.AddTrimSpaceFilter()
  4. info.AddSubstrFilter(start int, end int)
  5. info.AddToTitleFilter()
  6. info.AddToUpperFilter()
  7. info.AddToLowerFilter()
  8. info.AddXssFilter()
  9. info.AddXssJsFilter()
  10. form := table.NewDefaultTable(...).GetForm()
  11. form.AddLimitFilter(limit int)
  12. form.AddTrimSpaceFilter()
  13. form.AddSubstrFilter(start int, end int)
  14. form.AddToTitleFilter()
  15. form.AddToUpperFilter()
  16. form.AddToLowerFilter()
  17. form.AddXssFilter()
  18. form.AddXssJsFilter()