Can i Pass Other DOM Element's Value to Server while utilizing datatable's Server Side Processing.

Can i Pass Other DOM Element's Value to Server while utilizing datatable's Server Side Processing.

maulikDavemaulikDave Posts: 23Questions: 8Answers: 0

I Have Three text boxes and a Search button Which sends data to Controller on Click Event, and I am using DataTable ServerSide Processing to Process The data, I want That search button and DataTable to work in sync,

  • When I click on the search button it passes values of textboxes as well as DataTable Parameters which I can get in my MVC controller like int StartIndex = Convert.ToInt32(Request.Form["start"]);
  • When I change the page the data Which are in the text box also sent to the controller so I can perform sorting on them.

~~~~
Here is my Script


Value Of text Boxes var nameSearchVal = $("#searchByName").val().trim(); var amountSearchVal = $("#searchByAmount").val().trim(); var billingPeriodSearchVal = $("#searchByBillingPeriod").val().trim(); var newData = { nameSearchText: nameSearchVal, amountSearchText: amountSearchVal, billingPeriodSearchText: billingPeriodSearchVal }; $(document).ready(function () { $("#sTable").DataTable({ "ajax": { "url": "/ServerSide/GetProds", "type": "Post", "datatype": "json", "dataSrc" : "data" }, "columns": [ { "data": "id", "name": "Id","searchable": false, "sortable": false, "visible": false}, { "data": "name", "name": "Name" }, { "data": "description", "name": "Description" }, { "data": "price", "name": "Price" }, { "data": "prorate", "name": "Prorate" }, { "data": "billingPeriod", "name": "BillingPeriod" }, { "data": "createdDate", "name": "CreatedDate" }, ], "serverSide": "true", "order" : [0,"asc"], "pageLength": 5, "pagingType": "simple", "lengthChange": false, }); });

Here is MVC Contoller

 [HttpPost]
        public IActionResult GetProductListing(string nameSearchText = "", string amountSearchText = "", string 
        durationSearchText = "")
        {
            //int draw = Convert.ToInt32(Request.Form["draw"]);
            //int StartIndex = Convert.ToInt32(Request.Form["start"]);
            //string SortDir = Request.Form["order[0][dir]"];
            //int SortCol = Convert.ToInt32(Request.Form["order[0][column]"]);
            string SortDir = Request.Form["order[0][dir]"];
            int StartIndex = 0;

Is there any way I can do that?
I am new with dataTable Please Help.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923
    Answer ✓

    You can use ajax.data for this. The docs have a couple examples showing what you want to do.

    Kevin

  • maulikDavemaulikDave Posts: 23Questions: 8Answers: 0

    Thanks this Helped.

    Maulik

This discussion has been closed.