
|
If you were logged in you would be able to see more operations.
|
|
|
Data table column def should support types, like date, number, currency. Need to incorporate these into the DataTable and add formatters for them.
|
|
Description
|
Data table column def should support types, like date, number, currency. Need to incorporate these into the DataTable and add formatters for them. |
Show » |
Sort Order:
|
All the formatters worked fine except for 'date', which was because JSON doesn't handle date types. So in order to hook up your controllers to pass real JavaScript date-formatted objects back to the view, you have to use a utility method I added to the GrailsUITagLibService. For example, this came right out of the guidemo project:
def dataTableDataAsJSON = { def list = [] if (params.sort == 'crap') params.remove('sort') def demoList = Demo.list(params) response.setHeader("Cache-Control", "no-store") demoList.each { list << [ id: it.id, name: it.name, birthDate: grailsUITagLibService.dateToJs(it.birthDate), age: it.age, netWorth: it.netWorth, isDumb: it.isDumb, dataUrl: g.createLink(action: 'dataDrillDown') + "/$it.id" ] } def data = [ totalRecords: Demo.count(), results: list ] render data as JSON }As you can see, you send the 'birthDate' Date object into "dateToJs", and it will transform it into a string that will be recognized by the DataTable as a date in the view, and pulled back out into a JavaScript Date object for formatting.