Browse Source

DataTable ability to set field expression

Vova Tkach 6 years ago
parent
commit
9d057e469f
2 changed files with 7 additions and 1 deletions
  1. 6 1
      engine/builder/data_table.go
  2. 1 0
      modules/module_index.go

+ 6 - 1
engine/builder/data_table.go

@@ -11,6 +11,7 @@ import (
 
 type DataTableRow struct {
 	DBField     string
+	DBExp       string
 	NameInTable string
 	CallBack    func(values *[]string) string
 }
@@ -48,7 +49,11 @@ func DataTable(wrap *wrapper.Wrapper, table string, order_by string, order_way s
 		if column.NameInTable != "" {
 			result += `<th scope="col" class="col_` + column.DBField + `">` + html.EscapeString(column.NameInTable) + `</th>`
 		}
-		sql += " `" + column.DBField + "`"
+		if column.DBExp == "" {
+			sql += " `" + column.DBField + "`"
+		} else {
+			sql += " " + column.DBExp + " as `" + column.DBField + "`"
+		}
 		if i+1 < len(data) {
 			sql += ","
 		}

+ 1 - 0
modules/module_index.go

@@ -67,6 +67,7 @@ func (this *Modules) RegisterModule_Index() *Module {
 				},
 				{
 					DBField:     "datetime",
+					DBExp:       "UNIX_TIMESTAMP(`datetime`)",
 					NameInTable: "Date / Time",
 				},
 				{