Cannot read property 'asSorting' of undefined - DataTables
Syntax error... was missing a closing > on my initial table call. Check the very first line of my code.
Related videos on Youtube
Dudo
I like code. It's something I picked up as a hobby, and now I'm fortunate enough to be paid for it. My primary language is Ruby, but I'm trying out Elixir and Rust... functional languages in general. I ask a lot of questions, and I try to answer just as many.
Updated on September 16, 2022Comments
-
Dudo over 1 year
for ( j=0, jLen=oColumn.asSorting.length ; j<jLen ; j++ )
at line 6706 of DataTables...I copied the railscast on the topic, pretty much verbatim. So
oColumn
is undefined. The interwebs tell me that I need to have<thead>
and<th>
values...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, pretty much copied the 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 was able to get this to process, by adding
"aoColumns": [null, null, null, null, null, null]
. This nulls out the headers though, which defeats the purpose. This points to an issue with the headers being read though, and not the json, as the data returns just fine.ideas?