ajax-datatables-rails
の宝石を見つけようとしています。hereは運がありません。私のテーブルが表示され、正しいデータが(最初のページのために)ありますが、ページの検索、並べ替え、または変更を試みると、テーブルのデータは更新されません。Rails 4 + Datatables:Ajax-datatables-rails gemはテーブルを更新しません
シンプルなものがありますか?
ビュー
<table id="users-table" data-source="<%= users_path(format: :json) %>">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Admin?</th>
<th>Employee?</th>
<th>Client?</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
def index
respond_to do |format|
format.html
format.json { render json: UserDatatable.new(view_context) }
end
end
のDataTableコントローラ
class UserDatatable < AjaxDatatablesRails::Base
# uncomment the appropriate paginator module,
# depending on gems available in your project.
# include AjaxDatatablesRails::Extensions::Kaminari
include AjaxDatatablesRails::Extensions::WillPaginate
# include AjaxDatatablesRails::Extensions::SimplePaginator
def sortable_columns
# list columns inside the Array in string dot notation.
# Example: 'users.email'
@sortable_columns ||= [
'users.id',
'users.name',
'users.email',
'users.admin',
'users.employee',
'users.is_client'
]
end
def searchable_columns
# list columns inside the Array in string dot notation.
# Example: 'users.email'
@searchable_columns ||= [
'users.id',
'users.name',
'users.email',
'users.admin',
'users.employee',
'users.is_client'
]
end
private
def data
records.map do |record|
[
# comma separated list of the values for each cell of a table row
# example: record.attribute,
record.id,
record.name,
record.email,
record.admin,
record.employee,
record.is_client
]
end
end
def get_raw_records
# insert query here
User.all
end
# ==== Insert 'presenter'-like methods below if necessary
end
のJS
$('#users-table').dataTable({
"processing": true,
"serverSide": true,
"ajax": $('#users-table').data('source')
"pagingType": "full_numbers"
// optional, if you want full pagination controls.
// Check dataTables documentation to learn more about
// available options.
});
DOMReadyコールバックの '$( '#users-table').DataTable()'コールはありますか? – Uzbekjon
はい、他の関数がうまく呼び出されています。チャートがロードされ、更新はされず、ajaxリクエストはすべて同じように見えます –