0

我有一个日期搜索功能,可以在一次输入完整的日期输入时正常工作,例如:('10/30/2019')但是如果我输入它,例如:('10/')它会抛出一个 ajax 错误(屏幕截图随附的)。

我的 bal.js 文件:

$(document).ready(function() {
  $("table[role='bal_datatable']").each(function() {
    var table = $(this).DataTable({
      "order": [
        [7, "desc"]
      ],
      columnDefs: [{
          "searchable": false,
          "targets": 9
        },
        {
          "searchable": false,
          "targets": 10
        },
        {
          "orderable": false,
          "targets": 9
        },
        {
          "orderable": false,
          "targets": 10
        },
        {
          "className": "abc",
          "targets": [5]
        }
      ],
      autoWidth: false,
      pageLength: 50,
      processing: true,
      serverSide: true,
      ajax: $(this).data('url')
    });

    // Setup - add a text input to each footer cell
    $('#balances tfoot th').each(function(i) {
      var title = $(this).text();
      $(this).html('<input type="text" placeholder="' + title + '" />');


      $('input', this).on('keyup change', function() {
        if (table.column(i).search() !== this.value) {
          table
            .column(i)
            .search(this.value)
            .draw();
        }
      });

    });

  });
})

我的 bal_datatable.rb :

def bal_method1(balances)
  if(@tabular.search7 > '00/00/0000' )
    balances.where("balances.updated_at > (:search) and balances.updated_at < (date (:search) + interval '1 day')", {search: "#{@tabular.search7}"})
  else
    balances.where("1 = 1")
  end
end

图像显示在搜索文本框中输入“03/”后的错误

请帮忙。

4

1 回答 1

1
if( this.value.match(/(\d{2}\/\d{2}\/\d{4})/))
            { table.column(i).search( this.value ).draw(); }
            else if( this.value == '')
            { table.column(i).search( this.value ).draw(); }
于 2019-03-19T05:15:38.900 回答