Daterange

Daterange

rizkidsrizkids Posts: 1Questions: 1Answers: 0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

I want to create a filter by date range, but it doesn't output results.

In my database, the Datetime type is Time (yyyy-mm-dd hh:mm:ss), but when I want to view it only wants to display the date (dd/mm/yyyy). How do you do that?


following code in Controller:

public IActionResult Index(DateTime start, DateTime end, DateTime starts)
{
DateTime todayss = DateTime.Now;
string dateString = DateTime.Now.ToString("MM/dd/yyyy");

        JadwalMakanVM jadwalMakanVM = new JadwalMakanVM()
        {


            TransEmps = _db.TransEmp.Include(u => u.Employee)
            .Include(u => u.Employee.Departement)
            .ToList()


        };

        return View(jadwalMakanVM);
    }

Code in ViewModels:

public Employee Employee { get; set; }
public TransEmp TransEmp { get; set; }
public Departement Departement { get; set; }

    public IEnumerable<TransEmp> TransEmps { get; set; }
    public IEnumerable<Employee> Employees { get; set; }
    public IEnumerable<Departement> Departements { get; set; }

Code in Index:


Code in Javascripts:

var minDate, maxDate;

// Custom filtering function which will search data in column four between two values
$.fn.dataTable.ext.search.push(
function (settings, data, dataIndex, array) {

    var min = minDate.val();
    var max = maxDate.val();
    var date = new Date(data[0]);

    if (
        (min === null && max === null) ||
        (min === null && date <= max) ||
        (min <= date && max === null) ||
        (min <= date && date <= max)
    ) {
        return true;
    }
    return false;
}

);

$(document).ready(function () {
// Create date inputs
minDate = new DateTime($('#min'), {
format: 'DD/MM/YYYY'
});
maxDate = new DateTime($('#max'), {
format: 'DD/MM/YYYY'
});

// DataTables initialisation
var table = $('#example1').DataTable();

// Refilter the table
$('#min, #max').on('change', function () {
    table.draw();
});

});

Sign In or Register to comment.