beego datatables排序函数

datatables是个很不错的表格,使用GO时排序问题很麻烦,于是写了个函数,这是datatables1.8的

package tools

import (
	"github.com/astaxie/beego/context"
	"strconv"
)

//datatables的排序
func DT_order(aColumns []string, Input *context.BeegoInput) string {
	maps := make(map[string]string)
	if iSortCol_0, _ := strconv.Atoi(Input.Query("iSortCol_0")); iSortCol_0 > -1 {
		ranges, _ := strconv.Atoi(Input.Query("iSortingCols"))
		for i := 0; i < ranges; i++ {
			istring := strconv.Itoa(i)
			if iSortcol := Input.Query("bSortable_" + Input.Query("iSortCol_"+istring)); iSortcol == "true" {
				sordir := Input.Query("sSortDir_" + istring)
				thisSortCol, _ := strconv.Atoi(Input.Query("iSortCol_" + istring))
				if sordir == "asc" {
					maps[aColumns[thisSortCol]] = "asc"
				} else {
					maps[aColumns[thisSortCol]] = "desc"
				}
			}
		}
	}
	var order string
	if len(maps) > 0 {
		for k, v := range maps {
			if order == "" {
				order = k + " " + v
			} else {
				order += "," + k + " " + v
			}
		}
	}
	return order
}



使用方法:

order := models.DT_order([]string{"id", "username", "password"}, this.Ctx.Input)
fmt.Println(order)

转载于:https://my.oschina.net/tongjh/blog/357977

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值