Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/saulortega/datatables
Parser for DataTables (jQuery plugin)
https://github.com/saulortega/datatables
datatables go golang golang-library golang-package jquery parse server-side
Last synced: about 1 month ago
JSON representation
Parser for DataTables (jQuery plugin)
- Host: GitHub
- URL: https://github.com/saulortega/datatables
- Owner: saulortega
- License: gpl-3.0
- Created: 2018-02-23T15:01:30.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-01T19:57:52.000Z (almost 7 years ago)
- Last Synced: 2024-06-20T11:55:46.967Z (7 months ago)
- Topics: datatables, go, golang, golang-library, golang-package, jquery, parse, server-side
- Language: Go
- Homepage:
- Size: 34.2 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# datatables
Simple parser for [DataTables](https://datatables.net/) server-side processing.# Install
```
go get -u github.com/saulortega/datatables
```# Usage
```go
import "github.com/saulortega/datatables"//Parse receive *http.Request and returns a Filter struct
filter, err = datatables.Parse(r)
if err != nil {
//Handle error
}//Get data from DB
response := filter.PrepareResponse()
response.RecordsTotal = 629635
response.RecordsFiltered = 50
response.Data = rows//WriteResponse receive http.ResponseWriter. It send the response even if there are any error.
//Use WriteResponseOnSuccess(w) if you do not want to send the response when there is an error.
err := response.WriteResponse(w)
if err != nil {
//Handle error
}```
# Structs
```go
type Filter struct {
Draw int
Start int
Length int
Order []Order
Columns []Column
SearchValue string
SearchRegex bool
}type Column struct {
Data string
Name string
Index int
Orderable bool
Searchable bool
SearchValue string
SearchRegex bool
}type Order struct {
Column Column
Dir string
}
```