Serverside filtering for Datatables.Editor (.net/core)

Serverside filtering for Datatables.Editor (.net/core)

parcivalparcival Posts: 28Questions: 8Answers: 0
edited February 2019 in Free community support

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

Answers

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin
    Answer ✓

    You can apply conditions to the SQL data set through the Where method of the Editor instance. The documentation for that is available here.

    Allan

This discussion has been closed.