Serverside filtering for Datatables.Editor (.net/core)
Serverside filtering for Datatables.Editor (.net/core)
parcival
Posts: 28Questions: 8Answers: 0
I am trying to pre-filter a dataset (on mssql server), where the calling page may provide an initial filter. I think I recall having done something like this in the past, but I can't find my old code for the life of me.
I'd like to do something like build the filter dynamically based on a passed parameter, and that way reduce the maximum number of records that are going to be made available through the API.
public ActionResult ViewSessionLaunch(string month="any")
{
var filter = month == "any" ? "select * from ViewSessionLaunch" :
"select * from ViewSesionLaunch where month = '" + month + "'";
var dbConnection = config.GetSection("ConnectionStrings:Default").Value;
using (var db = new Database("sqlserver", dbConnection))
{
var response = new Editor(db, "ViewSessionLaunch", "id")
.Model<ViewSessionLaunchDT>()
.Process(Request)
.Data();
return Json(response);
}
}
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You can apply conditions to the SQL data set through the
Where
method of theEditor
instance. The documentation for that is available here.Allan