Browse Source

Ability to disable data table pagination

Vova Tkach 6 years ago
parent
commit
9ecad373c9
4 changed files with 49 additions and 39 deletions
  1. 45 36
      engine/builder/data_table.go
  2. 2 3
      modules/module_blog.go
  3. 1 0
      modules/module_index.go
  4. 1 0
      modules/module_users.go

+ 45 - 36
engine/builder/data_table.go

@@ -28,17 +28,24 @@ func DataTable(
 	pagination_url string,
 	custom_sql_count func() (int, error),
 	custom_sql_data func(limit_offset int, pear_page int) (*sql.Rows, error),
+	pagination_enabled bool,
 ) string {
 	var num int
 	var err error
-	if custom_sql_count != nil {
-		num, err = custom_sql_count()
-	} else {
-		err = wrap.DB.QueryRow("SELECT COUNT(*) FROM `" + table + "`;").Scan(&num)
-		if err != nil {
-			return ""
+
+	if pagination_enabled {
+		if custom_sql_count != nil {
+			num, err = custom_sql_count()
+		} else {
+			err = wrap.DB.QueryRow("SELECT COUNT(*) FROM `" + table + "`;").Scan(&num)
+			if err != nil {
+				return ""
+			}
 		}
+	} else {
+		num = 0
 	}
+
 	pear_page := 10
 	max_pages := int(math.Ceil(float64(num) / float64(pear_page)))
 	curr_page := 1
@@ -93,7 +100,7 @@ func DataTable(
 	result += `</tr>`
 	result += `</thead>`
 	result += `<tbody>`
-	if num > 0 {
+	if num > 0 || !pagination_enabled {
 		var rows *sql.Rows
 		var err error
 		if custom_sql_data == nil {
@@ -137,40 +144,42 @@ func DataTable(
 	result += `</tbody></table>`
 
 	// Show page navigation only if pages more then one
-	if max_pages > 1 {
-		result += `<nav>`
-		result += `<ul class="pagination" style="margin-bottom:0px;">`
-		class := ""
-		if curr_page <= 1 {
-			class = " disabled"
-		}
-		result += `<li class="page-item` + class + `">`
-		result += `<a class="page-link" href="` + pagination_url + `?p=` + fmt.Sprintf("%d", curr_page-1) + `" aria-label="Previous">`
-		result += `<span aria-hidden="true">&laquo;</span>`
-		result += `<span class="sr-only">Previous</span>`
-		result += `</a>`
-		result += `</li>`
-		for i := 1; i <= max_pages; i++ {
+	if pagination_enabled {
+		if max_pages > 1 {
+			result += `<nav>`
+			result += `<ul class="pagination" style="margin-bottom:0px;">`
+			class := ""
+			if curr_page <= 1 {
+				class = " disabled"
+			}
+			result += `<li class="page-item` + class + `">`
+			result += `<a class="page-link" href="` + pagination_url + `?p=` + fmt.Sprintf("%d", curr_page-1) + `" aria-label="Previous">`
+			result += `<span aria-hidden="true">&laquo;</span>`
+			result += `<span class="sr-only">Previous</span>`
+			result += `</a>`
+			result += `</li>`
+			for i := 1; i <= max_pages; i++ {
+				class = ""
+				if i == curr_page {
+					class = " active"
+				}
+				result += `<li class="page-item` + class + `">`
+				result += `<a class="page-link" href="` + pagination_url + `?p=` + fmt.Sprintf("%d", i) + `">` + fmt.Sprintf("%d", i) + `</a>`
+				result += `</li>`
+			}
 			class = ""
-			if i == curr_page {
-				class = " active"
+			if curr_page >= max_pages {
+				class = " disabled"
 			}
 			result += `<li class="page-item` + class + `">`
-			result += `<a class="page-link" href="` + pagination_url + `?p=` + fmt.Sprintf("%d", i) + `">` + fmt.Sprintf("%d", i) + `</a>`
+			result += `<a class="page-link" href="` + pagination_url + `?p=` + fmt.Sprintf("%d", curr_page+1) + `" aria-label="Next">`
+			result += `<span aria-hidden="true">&raquo;</span>`
+			result += `<span class="sr-only">Next</span>`
+			result += `</a>`
 			result += `</li>`
+			result += `</ul>`
+			result += `</nav>`
 		}
-		class = ""
-		if curr_page >= max_pages {
-			class = " disabled"
-		}
-		result += `<li class="page-item` + class + `">`
-		result += `<a class="page-link" href="` + pagination_url + `?p=` + fmt.Sprintf("%d", curr_page+1) + `" aria-label="Next">`
-		result += `<span aria-hidden="true">&raquo;</span>`
-		result += `<span class="sr-only">Next</span>`
-		result += `</a>`
-		result += `</li>`
-		result += `</ul>`
-		result += `</nav>`
 	}
 
 	return result

+ 2 - 3
modules/module_blog.go

@@ -114,11 +114,10 @@ func (this *Modules) RegisterModule_Blog() *Module {
 							node.id
 						ORDER BY
 							node.lft ASC
-						LIMIT ?, ?;`,
-						limit_offset,
-						pear_page,
+						;`,
 					)
 				},
+				true,
 			)
 		} else if wrap.CurrSubModule == "add" || wrap.CurrSubModule == "modify" {
 			if wrap.CurrSubModule == "add" {

+ 1 - 0
modules/module_index.go

@@ -158,6 +158,7 @@ func (this *Modules) RegisterModule_Index() *Module {
 				"/cp/"+wrap.CurrModule+"/",
 				nil,
 				nil,
+				true,
 			)
 		} else if wrap.CurrSubModule == "add" || wrap.CurrSubModule == "modify" {
 			if wrap.CurrSubModule == "add" {

+ 1 - 0
modules/module_users.go

@@ -96,6 +96,7 @@ func (this *Modules) RegisterModule_Users() *Module {
 				"/cp/"+wrap.CurrModule+"/",
 				nil,
 				nil,
+				true,
 			)
 		} else if wrap.CurrSubModule == "add" || wrap.CurrSubModule == "modify" {
 			if wrap.CurrSubModule == "add" {