datatables/README.md

64 lines
1.1 KiB
Markdown
Raw Normal View History

2018-02-23 23:01:30 +08:00
# datatables
2018-03-01 09:12:12 +08:00
Simple parser for [DataTables](https://datatables.net/) server-side processing.
2018-02-23 23:05:38 +08:00
2018-02-23 23:13:39 +08:00
# Install
```
2018-03-01 09:13:20 +08:00
go get -u github.com/saulortega/datatables
2018-02-23 23:13:39 +08:00
```
2018-02-23 23:05:38 +08:00
# Usage
2018-02-23 23:09:45 +08:00
```go
import "github.com/saulortega/datatables"
2018-02-23 23:13:39 +08:00
//Parse receive *http.Request and returns a Filter struct
2018-02-23 23:05:38 +08:00
filter, err = datatables.Parse(r)
if err != nil {
2018-02-23 23:09:45 +08:00
//Handle error
2018-02-23 23:05:38 +08:00
}
2018-03-02 03:55:38 +08:00
//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.
response.WriteResponse(w)
//
2018-02-23 23:09:45 +08:00
```
2018-02-23 23:05:38 +08:00
# Struct
2018-02-23 23:09:45 +08:00
```go
2018-02-23 23:05:38 +08:00
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
}
2018-02-23 23:07:08 +08:00
```