0

I am using some javascript to go out to ajax post but the issue I am having is the following. I am using Datatable version 1.9.4

<script type="text/javascript">

 $(function () {

     var myTable =  $('#allSubmissions').DataTable({
         'iDisplayLength': 15,
         "bSort": true,
         "sPaginationType": "full_numbers",           
         "bLengthChange": false,
         "bDestroy": true,
         "bRetreive": true,
         "searching": true,
     });

     $('#search-inp').on('keyup', function () {
         myTable.search($(this).val()).draw();
     });
 });

</script>

The issue I am having is that it says Search does not exist. The rest of the software is using DataTable which I must do the same any ideas as why it cant access https://datatables.net/ search function.

Also how does one replace the text box that is on the grid with the custom one basically I need to pass the values to a ajax post

c-sharp-and-swiftui-devni
  • 3,743
  • 4
  • 39
  • 100
  • You can remove var and try. Also, can you add full code, including html part, without full code it would be almost impossible to understand your issue. – Nesar Mar 30 '22 at 14:11
  • try remove var from "var myTable =" change to "myTable = " – Nesar Mar 30 '22 at 14:12
  • Its hard to as its a product cant share to much internal code – c-sharp-and-swiftui-devni Mar 30 '22 at 14:36
  • and var in javascript is actually very common – c-sharp-and-swiftui-devni Mar 30 '22 at 14:37
  • since it says "search does not exits", my guess is it can't access myTable object. myTable is not a global variable, and won't be available inside your onkeyup function. If you remove var, that will make myTable work like a global variable (kind of). you can read more about it in the question below. https://stackoverflow.com/questions/6888570/declaring-variables-without-var-keyword – Nesar Mar 30 '22 at 16:43
  • you don't need to share all code with real data, you can make a jsfiddle project to reproduce the error. so others can see what issue your are facing, and help you – Nesar Mar 30 '22 at 16:44
  • its not the table that cant be found its the function search if you actually read that article at all they recomend you not using a global style as it goes against javascript – c-sharp-and-swiftui-devni Mar 30 '22 at 21:58
  • maybe you missed my point. anyway, the issue seems not related to var. Did you add jquery.dataTables? https://cdnjs.cloudflare.com/ajax/libs/datatables/1.9.4/jquery.dataTables.min.js – Nesar Mar 31 '22 at 01:18
  • http://jsfiddle.net/ancytg8w/3/ check this jsfiddle snippet i made, it's working there. my guess is maybe jquery.datatable lib is missing. – Nesar Mar 31 '22 at 07:17
  • maybe its the 1.9.4 version maybe the search function is not in that one @Nesar – c-sharp-and-swiftui-devni Apr 01 '22 at 09:45

0 Answers0