How to send custom filter parameters to my backend?

How to send custom filter parameters to my backend?

lbelloqlbelloq Posts: 1Questions: 1Answers: 0

I'm using DataTables in serverside mode, and filtering works very well, but I have a question: one of the properties of my model is a DateTime field (properly mapped to the corresponding column and all) but I'd like to send, for filtering, a date range where either start or end dates can be NULL, and i's not a problem when I just need to compare one value in a column, but I don't know how to send two.

I'm using a custom field group outside the table to input filter parameters.

So, how do I add custom serverside filter parameters? Right now I'm doing this:

//Triggers table refresh, including sending filters
$('#btnfilter').click(function () {
    $('#tblUsers').DataTable().draw();
});
//Data table definition
$('#tblUsers').DataTable({
    "dom": "tipr",
    "pageLength": rows_per_page,
    "lengthChange": false,
    "processing": true,
    "serverSide": true,
    "ajax": {
        "url": source_url,
        "type": "POST",
        data: function (d) {
            var val = $('#txtUserName').val();
            if (val) {
                var col = columnas.filter(c => c.name === 'UserName')[0];
                if (col) {
                    //I simply add filter value to corresponding column definition and retrieve it serverside
                    col.search.value = val;
                }
            }
            var val_start_date = $('#txtStartDate').val();
            var val_end_date = $('#txtEndDate').val();
            if (val_start_date || val_end_date) {
                //What do I do here to send both dates?
            }
        }
    },
    "columns": [
        {
            "name": "UserName",
            "orderable": false,
            "render": function (data, type, row, meta) {
                return row.UserName;
            }
        },
        {
            "name": "CreationDate",
            "orderable": false,
            "render": function (data, type, row, meta) {
                return row.CreationDate;
            }
        },
        //Other columns, omitted for ease
    ]
});

Thanks in advance.

Answers

Sign In or Register to comment.