4

for ( j=0, jLen=oColumn.asSorting.length ; j<jLen ; j++ )DataTablesの6706行目..

私はこのトピックに関するrailscastをほぼ逐語的にコピーしました。したがってoColumn、未定義です。インターウェブは、私が持っている必要があり、価値観を持っていることを教えてくれ<thead>ます<th>...

見る:

<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>

これが新しいクラスのコピーです。繰り返しになりますが、railscastをほぼコピーしました

box_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(コーヒー):

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

を追加することで、これを処理することができました"aoColumns": [null, null, null, null, null, null]。ただし、これによりヘッダーが無効になり、目的が無効になります。これは、データが正常に返されるため、jsonではなく、ヘッダーが読み取られるという問題を示しています。

アイデア?

4

2 に答える 2

1

構文エラー...最初のテーブル呼び出しで終了>がありませんでした。コードの最初の行を確認してください。

于 2014-03-04T00:14:49.247 に答える
0

列データを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
               ]
于 2013-03-15T01:04:21.027 に答える