Created
March 16, 2011 21:11
-
-
Save mgreenly/873316 to your computer and use it in GitHub Desktop.
datatable.to_json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------------------------------------------------------------------------------------------------ | |
# type name description | |
#------------------------------------------------------------------------------------------------------------------ | |
# int iTotalRecords Total records, before filtering (i.e. the total number of records in | |
# the database) | |
# | |
# int iTotalDisplayRecords Total records, after filtering (i.e. the total number of records after | |
# filtering has been applied - not just the number of records being returned | |
# in this result set) | |
# | |
# string sEcho An unaltered copy of sEcho sent from the client side. This parameter will | |
# change with each draw (it is basically a draw count) - so it is important | |
# that this is implemented. Note that it strongly recommended for security | |
# reasons that you 'cast' this parameter to an integer in order to prevent | |
# Cross Site Scripting (XSS) attacks. | |
# | |
# string sColumns Optional - this is a string of column names, comma separated (used in | |
# combination with sName) which will allow DataTables to reorder data on the | |
# client-side if required for display | |
# | |
# array aaData The data in a 2D array | |
#----------------------------------------------------------------------------------------------------------------- | |
def to_json(params) | |
ActiveSupport::JSON.encode({ | |
:iTotalRecords => total_records(params), | |
:iTotalDisplayRecords => total_display_records(params), | |
:sEcho => (params.has_key?(:sEcho) ? params[:sEcho].to_i : -1), | |
:aaData => data(params) | |
}) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment