How to Sort Data in Rails App using ‘DataTable’ gem
Integrate this gem in the Rails application by putting this gem into gemfile.
Sorting data is inbuilt so instead of sortable_table gem use datatable gem and all columns are sortable in ascending and descending order.
In some cases, we have to hide searching, pagination functionality in table. For hiding pagination functionality we have to write "bPaginate": false and for hiding searching functionality we have to write "searching": false.
When you reload the page,you can see your listing page in better UI with sorting searching and pagination functionality.
The following steps with the description implements sorting,searching and pagination for particular table using datatable gem in our ruby on rails application easily.
STEP 1. gem install jquery-datatables-rails
STEP 3. Open app/assets/stylesheets/application.css and write : *= require dataTables/jquery.dataTables
STEP 4. Provide id for a particular table.) (table class="table table-bordered table-striped" id="myTable"
STEP 5. Call this table id by jQuery DataTable() function.Sample Code:
table class="table table-bordered table-striped" id="myTable"