github.com/kotovmak/go-admin@v1.1.1/template/components/table.go (about) 1 package components 2 3 import ( 4 "html/template" 5 6 "github.com/kotovmak/go-admin/template/types" 7 ) 8 9 type TableAttribute struct { 10 Name string 11 Thead types.Thead 12 InfoList []map[string]types.InfoItem 13 Type string 14 PrimaryKey string 15 Style string 16 HideThead bool 17 NoAction bool 18 Action template.HTML 19 EditUrl string 20 MinWidth string 21 DeleteUrl string 22 DetailUrl string 23 SortUrl string 24 UpdateUrl string 25 Layout string 26 IsTab bool 27 ExportUrl string 28 ActionFold bool 29 types.Attribute 30 } 31 32 func (compo *TableAttribute) SetThead(value types.Thead) types.TableAttribute { 33 compo.Thead = value 34 return compo 35 } 36 37 func (compo *TableAttribute) SetInfoList(value []map[string]types.InfoItem) types.TableAttribute { 38 compo.InfoList = value 39 return compo 40 } 41 42 func (compo *TableAttribute) SetType(value string) types.TableAttribute { 43 compo.Type = value 44 return compo 45 } 46 47 func (compo *TableAttribute) SetName(name string) types.TableAttribute { 48 compo.Name = name 49 return compo 50 } 51 52 func (compo *TableAttribute) SetHideThead() types.TableAttribute { 53 compo.HideThead = true 54 return compo 55 } 56 57 func (compo *TableAttribute) SetStyle(style string) types.TableAttribute { 58 compo.Style = style 59 return compo 60 } 61 62 func (compo *TableAttribute) SetMinWidth(value string) types.TableAttribute { 63 compo.MinWidth = value 64 return compo 65 } 66 67 func (compo *TableAttribute) SetLayout(value string) types.TableAttribute { 68 compo.Layout = value 69 return compo 70 } 71 72 func (compo *TableAttribute) GetContent() template.HTML { 73 if compo.MinWidth == "" { 74 compo.MinWidth = "1000px" 75 } 76 return ComposeHtml(compo.TemplateList, compo.Separation, *compo, "table") 77 } 78 79 type DataTableAttribute struct { 80 TableAttribute 81 EditUrl string 82 NewUrl string 83 UpdateUrl string 84 HideThead bool 85 DetailUrl string 86 SortUrl template.URL 87 DeleteUrl string 88 PrimaryKey string 89 IsTab bool 90 ExportUrl string 91 InfoUrl string 92 Buttons template.HTML 93 ActionJs template.JS 94 IsHideFilterArea bool 95 IsHideRowSelector bool 96 NoAction bool 97 HasFilter bool 98 Action template.HTML 99 ActionFold bool 100 types.Attribute 101 } 102 103 func (compo *DataTableAttribute) GetDataTableHeader() template.HTML { 104 return ComposeHtml(compo.TemplateList, compo.Separation, *compo, "table/box-header") 105 } 106 107 func (compo *DataTableAttribute) SetThead(value types.Thead) types.DataTableAttribute { 108 compo.Thead = value 109 return compo 110 } 111 112 func (compo *DataTableAttribute) SetLayout(value string) types.DataTableAttribute { 113 compo.Layout = value 114 return compo 115 } 116 117 func (compo *DataTableAttribute) SetIsTab(value bool) types.DataTableAttribute { 118 compo.IsTab = value 119 return compo 120 } 121 122 func (compo *DataTableAttribute) SetHideThead() types.DataTableAttribute { 123 compo.HideThead = true 124 return compo 125 } 126 127 func (compo *DataTableAttribute) SetButtons(btns template.HTML) types.DataTableAttribute { 128 compo.Buttons = btns 129 return compo 130 } 131 132 func (compo *DataTableAttribute) SetHideFilterArea(value bool) types.DataTableAttribute { 133 compo.IsHideFilterArea = value 134 return compo 135 } 136 137 func (compo *DataTableAttribute) SetActionJs(aj template.JS) types.DataTableAttribute { 138 compo.ActionJs = aj 139 return compo 140 } 141 142 func (compo *DataTableAttribute) SetActionFold(fold bool) types.DataTableAttribute { 143 compo.ActionFold = fold 144 return compo 145 } 146 147 func (compo *DataTableAttribute) SetHasFilter(hasFilter bool) types.DataTableAttribute { 148 compo.HasFilter = hasFilter 149 return compo 150 } 151 152 func (compo *DataTableAttribute) SetInfoUrl(value string) types.DataTableAttribute { 153 compo.InfoUrl = value 154 return compo 155 } 156 157 func (compo *DataTableAttribute) SetAction(action template.HTML) types.DataTableAttribute { 158 compo.Action = action 159 return compo 160 } 161 162 func (compo *DataTableAttribute) SetStyle(style string) types.DataTableAttribute { 163 compo.Style = style 164 return compo 165 } 166 167 func (compo *DataTableAttribute) SetExportUrl(value string) types.DataTableAttribute { 168 compo.ExportUrl = value 169 return compo 170 } 171 172 func (compo *DataTableAttribute) SetHideRowSelector(value bool) types.DataTableAttribute { 173 compo.IsHideRowSelector = value 174 return compo 175 } 176 177 func (compo *DataTableAttribute) SetUpdateUrl(value string) types.DataTableAttribute { 178 compo.UpdateUrl = value 179 return compo 180 } 181 182 func (compo *DataTableAttribute) SetDetailUrl(value string) types.DataTableAttribute { 183 compo.DetailUrl = value 184 return compo 185 } 186 187 func (compo *DataTableAttribute) SetSortUrl(value string) types.DataTableAttribute { 188 compo.SortUrl = template.URL(value) 189 return compo 190 } 191 192 func (compo *DataTableAttribute) SetPrimaryKey(value string) types.DataTableAttribute { 193 compo.PrimaryKey = value 194 return compo 195 } 196 197 func (compo *DataTableAttribute) SetInfoList(value []map[string]types.InfoItem) types.DataTableAttribute { 198 compo.InfoList = value 199 return compo 200 } 201 202 func (compo *DataTableAttribute) SetEditUrl(value string) types.DataTableAttribute { 203 compo.EditUrl = value 204 return compo 205 } 206 207 func (compo *DataTableAttribute) SetDeleteUrl(value string) types.DataTableAttribute { 208 compo.DeleteUrl = value 209 return compo 210 } 211 212 func (compo *DataTableAttribute) SetNewUrl(value string) types.DataTableAttribute { 213 compo.NewUrl = value 214 return compo 215 } 216 217 func (compo *DataTableAttribute) SetNoAction() types.DataTableAttribute { 218 compo.NoAction = true 219 return compo 220 } 221 222 func (compo *DataTableAttribute) GetContent() template.HTML { 223 if compo.MinWidth == "" { 224 compo.MinWidth = "1000px" 225 } 226 if !compo.NoAction && compo.EditUrl == "" && compo.DeleteUrl == "" && compo.DetailUrl == "" && compo.Action == "" { 227 compo.NoAction = true 228 } 229 return ComposeHtml(compo.TemplateList, compo.Separation, *compo, "table") 230 }