目前,我从数据库中获取了50条记录并将它们添加到数据表中。
@users = EvercamUser.all.includes(:country, :cameras).limit(50).order("created_at desc").decorate
但在页面加载后发送ajax请求并获取所有其他数千条记录并将其呈现到启动数据表的javascript页面。
我想要做的是在页面加载后已经存在的前50行之后绘制数据表,并希望在ajax成功之后绘制所有其他行。
我尝试了users_table.fnAddData(data)
,但它重写了整个datatable
,因为我要在50行之后加载。
数据表配置
users_table = undefined
initializeDataTable = ->
users_table = $("#users_datatables").DataTable
aaSorting: [1, "asc"]
aLengthMenu: [
[25, 50, 100, 200, -1]
[25, 50, 100, 200, "All"]
]
columns: [
{data: "0" },
{data: "1" },
{data: "2" },
{data: "3" },
{data: "4" },
{data: "5" },
{data: "6" },
{data: "7" },
{data: "8", visible: false },
{data: "9" }
],
iDisplayLength: 50
columnDefs: [
type: "date-uk"
targets: 'datatable-date'
],
"oLanguage": {
"sSearch": "Filter:"
},
initComplete: (data) ->
$("#user-list-row").removeClass('hide')
$("#users_datatables_length label").hide()
$("#div-dropdown-checklist").css('visibility', 'visible')
columnsDropdown = ->
$(".users-column").on "click", ->
column = users_table.column($(this).attr("data-val"))
column.visible !column.visible()
onPageLoad = ->
$(window).load ->
data = {}
data.true = true
$.ajax
url: 'users'
data: data
type: 'get'
dataType: "json"
success: (data) ->
users_table.fnAddData(data)