0

I am trying to set an external input to search a jquery datatable. Please see my view code:

<link href="~/Content/DataTables/css/jquery.dataTables.min.css" rel="stylesheet"/>
<link href="~/Content/DataTables/css/select.bootstrap.css" rel="stylesheet"/>

<script src="~/Scripts/DataTables/jquery.dataTables.min.js"></script>
<script src="~/Scripts/DataTables/dataTables.select.min.js"></script>
<script type="text/javascript">
    $(document)
    .ready(function() {
        var sfTable = $('#sfTable')
            .dataTable({
                "ajax": {
                    "url": "/Search/LoadData",
                    "type": "GET",
                    "datatype": "json"
                },
                "columns": [
                    { "data": "Id", "autoWidth": true },
                    { "data": "Name", "autoWidth": true },
                    { "data": "Address", "autoWidth": true }
                ],
                "searching": true,
                "select": true
            });

        $('#searchMe')
            .on('keyup',
                function() {
                    sfTable.search(this.value).draw();
                });
    });
</script>
<input id="searchMe" type="text"/>
<table id="sfTable" class="table table-condensed">
<thead>
<tr>
    <th>ID</th>
    <th>Name</th>
    <th>Address</th>
</tr>
</thead>
</table>

If I use the default searching in the rendered datatable it works fine, but using my custom SearchMe control doesn't search the table. My final goal is to have two datatables which are searched from a single input.

freedomn-m
  • 27,664
  • 8
  • 35
  • 57
Dominic Cotton
  • 789
  • 10
  • 34
  • Here You have! [link](https://stackoverflow.com/questions/5990386/datatables-search-box-outside-datatable?noredirect=1&lq=1) – Kaushik C Jan 25 '18 at 07:30

1 Answers1

0

Datatables - Search Box outside datatable

This led me to the answer, and it was really simple - the var sfTable = $('#sfTable').dataTable({ code had to be a capital D on DataTable() - suddenly it works!

Community
  • 1
  • 1
Dominic Cotton
  • 789
  • 10
  • 34