Not able to draw the table after deleting the row from datatable

Not able to draw the table after deleting the row from datatable

ChaundhyanChaundhyan Posts: 1Questions: 1Answers: 0
edited September 2016 in Free community support

Hi,
I'm trying to delete a row, if it does not fits the condition.(Basically, I need to add a date range filter).
I'm also using server side filters, so the client side custom filter is not working.

HTML:



Filter Clear Filter
Customer Name Date Time of Call Call Duration Satisfactory Rating Transcript

Javascript:
$(function() {
var url = document.URL + '/../LiveChatReport?chatWiseReport';
var $tableSel = $("#chatWise");
$tableSel.dataTable({
"bServerSide" : true,
"sAjaxSource" : url,
"bProcessing" : true,
"sPaginationType" : "full_numbers",
"bJQueryUI" : true,
"bDestroy" : true,
});

$('#clearFilter').on('click', function(e) {
    e.preventDefault();
    $.fn.dataTableExt.afnFiltering.length = 0;
    $('#start').val("");
    $('#end').val("");
});


$('#filter').on('click', function(e) {
    e.preventDefault();
    var startDate = $('#start').val(), endDate = $('#end').val();
    filterByDate(startDate, endDate); // We call our filter function
});

});

function filterByDate(startDate, endDate) {

var startDate = normalizeDate(startDate);
var endDate = normalizeDate(endDate);

var result = false;

var table = $('#chatWise').DataTable();
table.rows().every( function () {
    var d = this.data();
    var columnDate = normalizeColumnDate(d[1]);
    if(startDate <= columnDate && columnDate <= endDate){
        result = true;
    } else if(columnDate >= startDate && endDate === '' && startDate !== ''){
        result = true;
    } else if (columnDate <= endDate && startDate === '' && endDate !== '') {
        result = true;
    } else {
        result = false;
    }
    alert("Row deleting " + d);
    if(result == false){
        table
            .row(this)
            .remove()
            .draw();
    }
});

};

var normalizeDate = function(dateString) {
var date = new Date(dateString);
var normalized = date.getFullYear() + ''
+ (("0" + (date.getMonth() + 1)).slice(-2)) + ''
+ ("0" + date.getDate()).slice(-2);
return normalized;
};

var normalizeColumnDate = function(dateString) {
var day = dateString.substr(8,2);
var month = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'].indexOf(dateString.substr(4,3))+1;
var year = dateString.substr(dateString.length - 5);

var date = new Date(year+"-"+month+"-"+day);
var normalized = date.getFullYear() + ''
        + (("0" + (date.getMonth() + 1)).slice(-2)) + ''
        + ("0" + date.getDate()).slice(-2);
return normalized;

};

Looking forward for your help.

Mukul

This discussion has been closed.