按日期和数字过滤数据表

时间:2018-11-09 10:41:56

标签: javascript jquery ajax django api

嘿,我想过滤我的表格,当我按日期过滤其工作正常时,还有两个选项,按日期过滤和按数字过滤,当我删除按日期脚本过滤并尝试按支票编号过滤时,它会很好地工作,但是问题是当我同时使用两个脚本时它不起作用意味着当时它按日期而不是按支票号进行过滤...它给我错误检查日期不为空,但是如果我设置了任何检查日期然后按编号进行过滤比它只会过滤结果之间的选定日期,而不是搜索整个表格。

警告:数据表警告:表ID =数据表-无法重新初始化数据表。有关此错误的更多信息,请参见http://datatables.net/tn/3

<script>
$(document).ready(function(){
    //use a special class name or id for the table
    //using find I'm getting all tr elements in the table
    //using not(':eq(0)') I'm ignoring the first tr element
    //using each I'm iterating through the selected elements
    $('table').find('tr').not(':eq(0)').each(function(i){
        //using children('td:eq(0)') I'm getting the first td element inside the tr
        $(this).children('td:eq(0)').addClass('sno').text(i+1);
		
    });
});
</script>
<script>
$(document).ready(function(){
$("#divChqDate").hide();
	$("#divCheque").hide();
var table = $('#datatable').DataTable({
        
    });
  /* Initialise datatables */
  var oTable = $('#datatable').dataTable();

  $("#sea").click(function() {
    //Creating of our own filtering function
    $.fn.DataTable.ext.search.push(
        function(oSettings, aData, iDataIndex) {
        var min = parseInt( $('#min').val(), 10 );
        var max = parseInt( $('#max').val(), 10 );
           var Chequeno = parseInt(aData[2]);
           
        if ( ( isNaN( min ) && isNaN( max ) ) ||
             ( isNaN( min ) && Chequeno >= max ) ||
             ( min <= Chequeno   && isNaN( max ) ) ||
             ( min <=Chequeno    && Chequeno <= max ) )
        {
            return true;
        }
        return false;
    }
);

    //Update table
     oTable.fnDraw();
     //Deleting the filtering function if we need the original table later.

  });

});
</script>
<script>
 $(document).ready(function(){
 $("#divChqDate").hide();
	$("#divCheque").hide();
 var table = $('#datatable').DataTable({
        
    });
	$("#from").datepicker({ onSelect: function () { table.draw(); }, changeMonth: true, changeYear: true ,dateFormat: 'dd-mm-yy'});
            $("#to").datepicker({ onSelect: function () { table.draw(); }, changeMonth: true, changeYear: true,dateFormat: 'dd-mm-yy' });
		$.fn.dataTable.ext.search.push(
        function (settings, data, dataIndex) {
            var from = $('#from').datepicker("getDate");
            var to = $('#to').datepicker("getDate");
			//alert(from.getTime())
			//alert(to.getTime())
            var startDate = new Date(data[3]);
				if ((from.getTime() == null && to.getTime() == null) ||
					(from.getTime() == null && startDate.getTime() <= to.getTime()) ||
					(to.getTime() == null && startDate.getTime() >= from.getTime()) ||
					(startDate.getTime() <= to.getTime() && startDate.getTime() >= from.getTime()) )
			{
				return true; 
			}
            return false;
        }
        );
		table.on( 'order.dt search.dt', function () {
        table.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
            cell.innerHTML = i+1;
        } );
    } ).draw();
       // Event listener to the two range filtering inputs to redraw on input
            $('#from, #to').change(function () {
             oTable.fnDraw();
            });
        });
       



function getval(sel)
{
	if	(sel.value == 1)
	{
	$("#divChqDate").show();
	$("#divCheque").hide();
	
	//reloadTable();
	}
	else if(sel.value == 2)
	{
	$("#divChqDate").hide();
	$("#divCheque").show();
	}
    //alert(sel.value);
}
</script>
<body>
<div class="container">
<form action="/cheque/report/" name="report">
Search By :<select id="topay" onchange="getval(this);">
			<option value="0">Select Option</option>
			<option value="1">Cheque Date</option>
			<option value="2">Cheque No.</option>
</select>
<div id="divChqDate">
<b><p>Cheque Date:</p>
From: <input id="from" autocomplete="off"/>
To: <input id="to" autocomplete="off"/>
<button type="button" onclick="location.reload();">Refresh</button>
<button onclick="printDiv();">Print it</button></b>
</div>
<br><br>
<div id="divCheque">
<b><p>Cheque No: </p> 
From: <input id="min"  name="min"  autocomplete="off" maxlength="6" />
To: <input id="max"  name="max"  autocomplete="off" maxlength="6" />
<button type="button" id="sea">Search</button></b>
</div>
<div id="print-content">
<b><u><h2 align="center">Details of Cheque</h2></b></u>
<table id="datatable" name="table" class="display" >
<thead>
  <tr>
	<th>S.No</th>
    <th>To_Pay   </th>
    <th> Cheque_No </th>
    <th>Cheque_Date</th>
    <th>Entry_Date</th>
	<th> Remarks </th>
	</tr>
</thead>
 <tbody>	
 {% for report in reports %}
  <tr>
    <td class="sno"></td>
	<td>{{report.topay}}</td>
    <td>{{report.chequeno}}</td>
    <td>{{report.chequedate | date:"Y-m-d"}}</td>
    <td>{{report.date | date:"Y-m-d"}}</td>
	<td>{{report.remarks}}</td>
	
  </tr>
 {% endfor %}
  <tbody>
</table>
<br><br>
</form>
</div>
</div>
</body>

0 个答案:

没有答案