Performing auto search

Performing auto search

jayshettijayshetti Posts: 6Questions: 1Answers: 0

Hello how can i initialize value to search box and sort based on value initialized without human interaction. It should be done programatically is there any way to archive this?

Thanks,

Answers

  • gyrocodegyrocode Posts: 126Questions: 6Answers: 30
    edited July 2017

    Use search.search option to set an initial filtering condition on the table. After initialization this could be done with search() method followed by draw() method.

    Use order option to set initial order during initialization. After initialization this could be done with order() method followed by draw() method.


    See more articles about jQuery DataTables on gyrocode.com.

  • jayshettijayshetti Posts: 6Questions: 1Answers: 0
    edited July 2017

    Hi @gyrocode I am able to initialise value to search box but unable perform auto search

    ` $(document).ready(function() {
    var table= $("#dataTables-example").DataTable({
    responsive: true,
    "bPaginate": true,
    "bLengthChange": false,
    "pageLength": 2,
    "bFilter": true,
    "bInfo": false,
    "bAutoWidth": false,
    "ordering": false,
    "rowsGroup": [2],
    "oSearch": {"sSearch": " hg"},
    "language": {
    "search": "Find: ",

    },

        });
    

    });
    `

    could you guide me how can use search() and draw() with this.

  • gyrocodegyrocode Posts: 126Questions: 6Answers: 30

    See this example for demonstration of using search.search option.


    See more articles about jQuery DataTables on gyrocode.com.

  • jayshettijayshetti Posts: 6Questions: 1Answers: 0
    edited July 2017

    @gyrocode i used your example and included it in my code something like this.
    var tables= $('#example').DataTable({
    responsive: true,
    "bPaginate": true,
    "bLengthChange": false,
    "pageLength": 2,
    "bFilter": true,
    "bInfo": false,
    "bAutoWidth": false,
    "ordering": false,
    "rowsGroup": [2],
    search: {
    search: '34'
    }
    });

    but it is not performing search for me it only initialises value. But when i copied above snippet into your shared example it is working fine.
    what could be the reason.

  • allanallan Posts: 63,480Questions: 1Answers: 10,467 Site admin

    Possibly you are using an old version of DataTables? Hard to say without a test case - can you link to one please.

    Allan

  • jayshettijayshetti Posts: 6Questions: 1Answers: 0

    Hi @allan where can i get newer version of DataTables?

  • allanallan Posts: 63,480Questions: 1Answers: 10,467 Site admin

    The download page :).

    I don't know if you are using an old version - as I say, without a test case I don't know.

    Allan

  • jayshettijayshetti Posts: 6Questions: 1Answers: 0
    edited July 2017

    Hello @allan
    there is no problem with version.
    Let me tell you what exactly i am trying to do.
    I am fetching data from SQL in php and populating all fetched data into Table with customised UI.
    To display it in table i am using Datatables.

    var tables= $('#example').DataTable({
    responsive: true,
    "bPaginate": true,
    "bLengthChange": false,
    "pageLength": 2,
    "bFilter": true,
    "bInfo": false,
    "bAutoWidth": false,
    "ordering": false,
    "rowsGroup": [2],
    search: {
    search: '34'
    }
    });
    when i do this it only initialises value 34 into search box but it does not perform search at all.
    My ultimate aim is to display pagination at bottom when page get loaded with all data by performing auto search.
    When i hit enter or space button into search box it performs search operation.

  • allanallan Posts: 63,480Questions: 1Answers: 10,467 Site admin

    We'd need a link to a test case showing the issue. @gyrocode showed the search.search option working as expected.

    Allan

  • jayshettijayshetti Posts: 6Questions: 1Answers: 0

    @allan i sent you link to your inbox.

  • allanallan Posts: 63,480Questions: 1Answers: 10,467 Site admin

    Thanks for the link. There is a Javascript error happening on the page which is stopping the search from happening. That appears to be caused by an empty row (<tr></tr>) in the thead element.

    Allan

This discussion has been closed.