where can I find the ajax call function for search box?

where can I find the ajax call function for search box?

ikelcaikelca Posts: 19Questions: 7Answers: 0
edited September 2019 in Free community support

I know there is ajax call while I typing in search box, in case of server side processing, the query is sent to server by ajax,

so where exactly can I find that ajax function corresponding to searchbox?

many thanks

Answers

  • ikelcaikelca Posts: 19Questions: 7Answers: 0

    just to clarify, i want to customize searchbox so that I can only search one column from database

    really appreciated

  • kthorngrenkthorngren Posts: 21,160Questions: 26Answers: 4,921

    This example shows one way to create your own event for the default search input.
    http://live.datatables.net/jorexujo/1/edit

    You can replace the search() API part with column().search().

    Another option is to remove the global search input using the dom option and create your own input that uses column().search().

    Kevin

  • ikelcaikelca Posts: 19Questions: 7Answers: 0
    edited September 2019

    maybe some api for replacing the function from exiting searchbox?
    i'd like to keep the existing searchbox where it is, but replacing the function is good idea.

    i tried with searching:false, and found that removes searchbox.

    is there any way we can keep searchbox but replacing its function?

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    This is another example of Kevin's that calls off() to remove the existing listeners - you can then apply your own. It came from this thread.

    Cheers,

    Colin

  • kthorngrenkthorngren Posts: 21,160Questions: 26Answers: 4,921

    Sorry, should have provided a more complete example. The first example I provided also uses off(). I modified it to just search column 0.
    http://live.datatables.net/jorexujo/25/edit

    Here is the resulting code:

          $('.dataTables_filter input')
           .off()
           .on('keyup', function() {
              $('#example').DataTable().column(0).search(this.value.trim(), false, false).draw();
           });    
    
    

    Kevin

  • ikelcaikelca Posts: 19Questions: 7Answers: 0
    edited September 2019

    thank you for all examples,
    with this

    $('#itemDetailsTable_filter input')
         .off()
         .on('keyup', function() {
                 $('#itemDetailsTable').DataTable().column(0).search(this.value.trim(), false, false).draw(); 
         });
    

    } );

    i somehow got it following error for console:

    jquery.dataTables.min.js:40 Uncaught TypeError: Cannot read property 'length' of undefined
    at wb (jquery.dataTables.min.js:40)
    at jquery.dataTables.min.js:37
    at i (jquery.dataTables.min.js:35)
    at Object.success (jquery.dataTables.min.js:36)
    at fire (jquery-3.3.1.js:3268)
    at Object.fireWith [as resolveWith] (jquery-3.3.1.js:3398)
    at done (jquery-3.3.1.js:9305)
    at XMLHttpRequest.<anonymous> (jquery-3.3.1.js:9548)

    this is error is from reponse:

    {"error":"An SQL error occurred: SQLSTATE[IMSSP]: Tried to bind parameter number 65536. SQL Server supports a maximum of 2100 parameters."}

    is this related to mssql server i'm using at back end?

  • kthorngrenkthorngren Posts: 21,160Questions: 26Answers: 4,921

    Are you using server side processing, ie, serverSide: true?

    If so what are you using for the server script?

    Kevin

  • ikelcaikelca Posts: 19Questions: 7Answers: 0
    edited September 2019

    yes, i am using serverSide:true
    and i copied from ssp.class.php from example here https://github.com/DataTables/DataTablesSrc/blob/master/examples/server_side/scripts/ssp.class.php

    the only thing is that Im using MSSQL SERVER 2012 at back end
    the datatable loads correctly, it is the search ajax giving this error somehow, i have spent hours to figure what's wrong, but it guess it has something to do with syntax of MSSQL being different from MYSQL. but im not quite sure how to fix it yet.

    at beginning, i thought the table has too many columns( actually only 150 columns), but same error still happens after i switch to small table with only 10 columns.

  • ikelcaikelca Posts: 19Questions: 7Answers: 0

    is there any way we can show the sql query from ssp.class.php ? i'm having hard time to figure out where the query has wrong, or maybe something else.

  • allanallan Posts: 63,180Questions: 1Answers: 10,411 Site admin

    You could comment this line back in - it will give an JSON error, but you can ignore that while debugging.

    One thing - that script is for MySQL. You'd need to modify it to work with SQL Server.

    Allan

This discussion has been closed.