When working with datatables server-side proccessing. How does the search value being passed to the server? I've looked in the doc.
The datatable sends automatically the draw, start and the length to the server. Can and should I do something simular with the search? The documentation mention search[value] but I don't know how to interpretive it.
CLIENT
$(document).ready(function () {
    var url = '@Url.Action("GetJsonData", "Home")';
    $('#example').dataTable({
        'searching': true,
        "paging": true,
        "processing": true,
        "serverSide": true,
        "ajax": {
            "url": url,
            "type": "GET"
        },
        "columns": [
            { "data": "id" },
            { "data": "name" }
        ]
    });
});
SERVER
public JsonResult GetJsonData(string draw, int start, int length, string search)
{
    var hugeDataArr = new object[100];
    var returnDataArr = new object[length];
    for (int i = 0; i < hugeDataArr.Length; i++)
    {
        hugeDataArr[i] = new
        {
            DT_RowId = i, 
            id = "id" + i.ToString().PadLeft(2, '0'), 
            name = "nameæøå" + i.ToString().PadLeft(2, '0')
        };
    }
    for (int i = 0; i < length; i++)
    {
        returnDataArr[i] = hugeDataArr[start + i];
    }
    JsonResult json = Json(new
    {
        draw = Convert.ToInt32(draw),
        recordsTotal = 100, // calculated field
        recordsFiltered = 50, // calculated field
        data = returnDataArr
    }, JsonRequestBehavior.AllowGet);
    return json;
}
                You are not supposed to use search as parameter.But it automatically is part of your query string.
public JsonResult GetJsonData(string draw, int start, int length)
{
     string search = Request.QueryString["search[value]"];
     // your code for search filtering
}
thanks ravi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With