SSP

package module
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2020 License: MIT Imports: 7 Imported by: 0

README

gormssp

Using Datatables pagination with golang

Build Status Go Report Card codecov MIT licensed GoDoc GitHub release (latest by date) GitHub All Releases

Pre-requisites 📋
Installation 🔧

Install whit the next command:

go get github.com/juaismar/gormssp

and import the package with:

import ("github.com/juaismar/gormssp")

Working example 🚀

-// TODO, show a better example

import ("github.com/juaismar/gormssp")

func (c *User) Pagination() {

  // Array of database columns which should be read and sent back to DataTables.
  // The `db` parameter represents the column name in the database, while the `dt`
  // parameter represents the DataTables column identifier. In this case simple
  // indexes
  // Formatter is a function to customize the value of field , can be nil.
  columns := make(map[int]SSP.Data)
  columns[0] = SSP.Data{Db: "name", Dt: 0, Formatter: nil}
  columns[1] = SSP.Data{Db: "role", Dt: 1, Formatter: nil}
  columns[2] = SSP.Data{Db: "email", Dt: 2, Formatter: nil}

  // Send the data to the client
  c.Data["json"] = SSP.Simple(c, model.ORM, "users", columns)
  c.ServeJSON()
}

-This project is based in the PHP version of datatables pagination in https://datatables.net/examples/data_sources/server_side -

Author ✒️

Thanks 🎁

Readme.md based in https://gist.github.com/Villanuevand/6386899f70346d4580c723232524d35a

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	Db        string                                                         //name of column
	Dt        interface{}                                                    //id of column in client (int or string)
	Cs        bool                                                           //case sensitive - optional default false
	Formatter func(data interface{}, row map[string]interface{}) interface{} // - optional
}

type MessageDataTable

type MessageDataTable struct {
	Draw            int           `json:"draw"`
	RecordsTotal    int           `json:"recordsTotal"`
	RecordsFiltered int           `json:"recordsFiltered"`
	Data            []interface{} `json:"data,nilasempty"`
}

func Complex

func Complex(c interface {
	GetString(string, ...string) string
}, conn *gorm.DB, table string, columns map[int]Data,
	whereResult []string, whereAll []string) MessageDataTable

func Simple

func Simple(c interface {
	GetString(string, ...string) string
}, conn *gorm.DB,
	table string,

	columns map[int]Data) MessageDataTable

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL