DataTables过滤器不包含JSON数据中的范围编号

时间:2016-04-28 15:28:01

标签: javascript jquery datatables datatables-1.10

我遇到了这个问题。 DataTables没有从JSON加载的范围编号。

我尝试过滤第四列data[3]。 chrome控制台不显示任何错误。 我可以看到'处理' modal虽然在输入字段中输入数字,但它什么也没做。

我的脚本如下所示:

(function(){
$.fn.dataTable.ext.search.push(
    function( settings, data, dataIndex ) {
        var min = parseInt( $('#min_room').val(), 10 );
        var max = parseInt( $('#max_room').val(), 10 );
        var rooms = parseFloat( data[3] ) || 0;

        if ( ( isNaN( min ) && isNaN( max ) ) ||
             ( isNaN( min ) && rooms <= max ) ||
             ( min <= rooms   && isNaN( max ) ) ||
             ( min <= rooms   && rooms <= max ) )
        {
            return true;
        }
        return false;
    }
);

$(document).ready(function() {
    $('#datatabletest').DataTable({

    "order": [[ 0, "desc" ]],
    "deferRender": true,
    "processing": true,
    "serverSide": true,
    "ajax": "http://www.site.ru/jsonfile/"
});


    var table = $('#datatabletest').DataTable();

    $('#min_room, #max_room').keyup( function() {
        table.draw();
    });
});
})();

json文件由django-datatables-view创建,如下所示:

{
  "recordsTotal": 129,
  "recordsFiltered": 129,
  "draw": 0,
  "data": [
    [
      "2016-04-04",
      "Твардовского 22/5",
      "м-н КСМ",
      1,
      1250,
      2,
      "Наталья"
    ],
    [
      "2016-01-17",
      "Крылова 4",
      "м. Красный проспект",
      4,
      32000,
      107,
      "Собственник"
    ], ...

我的html文件的表格部分:

<form>
            <div class="form-group col-xs-2 form_block_style">
              <label class="col-sm-12">Число комнат:</label>
              <div class="col-sm-6">
                <input type="text" id = "min_room" placeholder="0" class="form-control">
              </div>
              <div class="col-sm-6">
                <input type="text" id="max_room" placeholder="5" class="form-control">
              </div>
            </div>
          </form>

<table id="datatabletest" class="table table-striped table-bordered" cellspacing="0">
            <thead>
              <tr>
                <th>td1</th>
                <th>td2</th>
                <th>td3</th>
                <th>td4</th>
                <th>td5</th>
                <th>td6</th>
                <th>td7</th>
              </tr>
            </thead>
            <tfoot>
              <tr>
                <th>td1</th>
                <th>td2</th>
                <th>td3</th>
                <th>td4</th>
                <th>td5</th>
                <th>td6</th>
                <th>td7</th>
              </tr>
            </tfoot>
          </table>

0 个答案:

没有答案