Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Team

I am bit struggling to search for values on my tables, using dataTables on my view.chsmtl. How do i do this, meaning i want to search for table values if they exist if not must be jquery error handler? Here is my View.cshtml i am using dataTable and want to use search to filter out values from the table on the database.

What I have tried:

// controller class

[HttpPost]
   public ActionResult GetList()
    {
        //Server side Parameter.
        int start = Convert.ToInt32(Request["start"]);
        int length = Convert.ToInt32(Request["length"]);
        string searchValue = Request["search[value]"];
        string sortColumnName = Request["columns[" + Request["order[0][column]"] + "][name]"];
        string sortDirection = Request["order[0] [dir]"];





        return View();
    }




C#
<pre>
@{
    ViewBag.Title = "EventManagement List";
}
<hr/>
<hr/>
<hr/>
<h2>EventManagement List</h2>
<table id="EventManagementTable" class="display">
    @*Semantic UI*@
    @*<table id="EventManagementTable" class="ui celled table">*@
    @*Bootstrap*@
    @*<table id="EventManagementTable" class="table table-striped table-bordered">*@

    <thead>
        <tr>
            <th>TrainingID</th>
            <th>TrainingType</th>
            <th>TrainingDescription</th>
            <th>Price</th>
            <th>Venue</th>
            <th>Facilitator</th>
            <th>WhoAttend</th>
            <th>RSVP</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th>TrainingID</th>
            <th>TrainingType</th>
            <th>TrainingDescription</th>
            <th>Price</th>
            <th>Venue</th>
            <th>Facilitator</th>
            <th>WhoAttend</th>
            <th>RSVP</th>
        </tr>
    </tfoot>

</table>


<!--Normal DataTables-->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.20/datatables.min.css" />

<!---JQuery ThemeRoller-->
<link href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<link href="https://cdn.datatables.net/1.10.15/css/dataTables.jqueryui.min.css" rel="stylesheet" />

<!--Semantic UI-->
<link href="//cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.6/semantic.min.css" rel="stylesheet" />
<link href="https://cdn.datatables.net/1.10.15/css/dataTables.semanticui.min.css" rel="stylesheet" />

<!-- Bootstrap 4 -->
<link href="https://cdn.datatables.net/1.10.15/css/dataTables.bootstrap4.min.css" rel="stylesheet" />

@section scripts{
    
    <script src="//cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/1.10.15/js/dataTables.jqueryui.min.js"></script>
    <script src="https://cdn.datatables.net/1.10.15/js/dataTables.semanticui.min.js"></script>
    <link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0.0-alpha.6/css/bootstrap.css" rel="stylesheet"/>
    <script src="https://cdn.datatables.net/1.10.15/js/dataTables.bootstrap4.min.js"></script>

    <script>

     $(document).ready(function () {

            $("#EventManagementTable").DataTable(
                {
                    "ajax": {
                        "url": "/EventManagement/GetList",
                        "type": "GET",
                        "datatype": "json"
                    },
                    "columns": [
                        { "data": "TrainingID" },
                        { "data": "TrainingType" },
                        { "data": "TrainingDescription" },
                        { "data": "Price" },
                        { "data": "Facilitator" },
                        { "data": "WhoAttend" },
                        {"data":"RSVP"}
                    ],
  "serverSide": "true",
                    "order": [0, "asc"],
                    "processing": "true",
                    "language": {
                        "processing":"processing...... please wait"
                    }


                });

     });

        
    </script>

    
    }
Posted
Updated 10-Feb-20 3:16am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900