Ruby on rails 无法读取属性';分类';未定义数据表的定义
Ruby on rails 无法读取属性';分类';未定义数据表的定义,ruby-on-rails,ruby-on-rails-3,datatables,Ruby On Rails,Ruby On Rails 3,Datatables,for(j=0,jLen=oColumn.sorking.length;j如果您希望将列数据绑定到json,那么您应该将代码更改为: $('#companyBoxList').dataTable sPaginationType: "full_numbers", bJQueryUI: true, bProcessing: true, bServerSide: true, sAjaxSource: $('#companyBoxList').data('sour
for(j=0,jLen=oColumn.sorking.length;j如果您希望将列数据绑定到json,那么您应该将代码更改为:
$('#companyBoxList').dataTable
sPaginationType: "full_numbers",
bJQueryUI: true,
bProcessing: true,
bServerSide: true,
sAjaxSource: $('#companyBoxList').data('source'),
aoColumns: [{"mDataProp": "uId"},
.....the other data that you want to add such as length and width
]
语法错误…在我的初始表调用中缺少一个结束>。请检查我代码的第一行。我不知道Rail,但datatables还可以,您能简单解释一下问题吗?不要放入aoColumns:[null,null,null,null,null,null]
在我的javascript中,它出错了,声称它找不到oColumn对象。好吧,我知道原因是什么。参考我的答案,如果有其他问题,请发表评论,让我们一起前进,顺便说一句,因为我知道Rail非常棒。天哪,我很笨。在
调用开始时错过了
。哇,我不这么认为原因是这样的,但可能是这样。我发布了一些更改后的代码,希望能给您一些想法。另外请注意服务器返回的json格式
class BoxesDatatable
delegate :params, :h, :link_to, :number_to_currency, to: :@view
def initialize(view)
@view = view
end
def as_json(options = {})
{
sEcho: params[:sEcho].to_i,
iTotalRecords: Box.count,
iTotalDisplayRecords: boxes.count,
aaData: data
}
end
private
def data
boxes.map do |box|
[
box.uid,
box.length,
box.width,
box.height,
box.weight,
box.trips
]
end
end
def boxes
@boxes ||= fetch_boxes
end
def fetch_boxes
boxes = Box.order("#{sort_column} #{sort_direction}")
boxes = boxes.page(page).per(per_page)
if params[:sSearch].present?
boxes = boxes.where("uid like :search or trips like :search", search: "%#{params[:sSearch]}%")
end
boxes
end
def page
params[:iDisplayStart].to_i/per_page + 1
end
def per_page
params[:iDisplayLength].to_i > 0 ? params[:iDisplayLength].to_i : 10
end
def sort_column
columns = %w[uid length width height weight trips]
columns[params[:iSortCol_0].to_i]
end
def sort_direction
params[:sSortDir_0] == "desc" ? "desc" : "asc"
end
end
jQuery ->
$('#companyBoxList').dataTable
sPaginationType: "full_numbers"
bJQueryUI: true
bProcessing: true
bServerSide: true
sAjaxSource: $('#companyBoxList').data('source')
$('#companyBoxList').dataTable
sPaginationType: "full_numbers",
bJQueryUI: true,
bProcessing: true,
bServerSide: true,
sAjaxSource: $('#companyBoxList').data('source'),
aoColumns: [{"mDataProp": "uId"},
.....the other data that you want to add such as length and width
]