Unable to read "asSorting" property from undefined - DataTables

for ( j=0, jLen=oColumn.asSorting.length ; j<jLen ; j++ ) on line 6706 of the data tables ...

I copied railscast on this subject, quite a few verbatim. So oColumn undefined. The relationship tells me that I need to have the values <thead> and <th> ...

View:

 <table id="companyBoxList" class="display" data-source="<%= comp_boxes_path(format: "json") %>" <thead> <tr> <th>uid</th> <th>length</th> <th>width</th> <th>height</th> <th>weight</th> <th>trips</th> </tr> </thead> <tbody> </tbody> </table> 

Here is a copy of the new class. Again, heavily copied railscast

boxes_database.rb

 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 

javascript (coffee):

 jQuery -> $('#companyBoxList').dataTable sPaginationType: "full_numbers" bJQueryUI: true bProcessing: true bServerSide: true sAjaxSource: $('#companyBoxList').data('source') 

I managed to handle this by adding "aoColumns": [null, null, null, null, null, null] . However, this excludes headers that defeat the target. This indicates a problem with reading the headers and not with json as the data returned is just fine.

ideas?

+4
source share
2 answers

Syntax error ... missing closing> in my initial table call. Check out the first line of my code.

+1
source

If I'm not mistaken that you want to bind the column data to json, so you should change the code:

 $('#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 ] 
0
source

Source: https://habr.com/ru/post/1469388/


All Articles