You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 1.1 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # datatables
  2. Simple parser for [DataTables](https://datatables.net/) server-side processing.
  3. # Install
  4. ```
  5. go get -u github.com/saulortega/datatables
  6. ```
  7. # Usage
  8. ```go
  9. import "github.com/saulortega/datatables"
  10. //Parse receive *http.Request and returns a Filter struct
  11. filter, err = datatables.Parse(r)
  12. if err != nil {
  13. //Handle error
  14. }
  15. //Get data from DB
  16. response := filter.PrepareResponse()
  17. response.RecordsTotal = 629635
  18. response.RecordsFiltered = 50
  19. response.Data = rows
  20. //WriteResponse receive http.ResponseWriter. It send the response even if there are any error.
  21. //Use WriteResponseOnSuccess(w) if you do not want to send the response when there is an error.
  22. err := response.WriteResponse(w)
  23. if err != nil {
  24. //Handle error
  25. }
  26. ```
  27. # Structs
  28. ```go
  29. type Filter struct {
  30. Draw int
  31. Start int
  32. Length int
  33. Order []Order
  34. Columns []Column
  35. SearchValue string
  36. SearchRegex bool
  37. }
  38. type Column struct {
  39. Data string
  40. Name string
  41. Index int
  42. Orderable bool
  43. Searchable bool
  44. SearchValue string
  45. SearchRegex bool
  46. }
  47. type Order struct {
  48. Column Column
  49. Dir string
  50. }
  51. ```