Best way to load a table with string parm

Best way to load a table with string parm

bgdatatblbgdatatbl Posts: 5Questions: 0Answers: 0
edited March 2014 in General
I am looking for some sample code for someone to enter a string into a text box, hit submit, and then load a datatable. I have built datatables but the issues I am having is for the text to make it to the server side code so that I can search on this code. Also, if someone clicks the button over and over, I am having issues with table loading correctly. Any sample code that could show the best implementation of this? Do I load the table in a var and rebuild every time?

Replies

  • allanallan Posts: 63,302Questions: 1Answers: 10,431 Site admin
    Very happy to write sample code on my freelance rate for you ;-).

    In all seriousness, what have you tried so far? Can you show us the code / link to the page? Are you destroying the table on each click, or just reloading the ajax data?

    Allan
  • bgdatatblbgdatatbl Posts: 5Questions: 0Answers: 0
    I'm using an example on the internet to prep for the bigger solution I am trying to get working.

    The following is in my index file

    [code]

    $(document).ready(function() {
    var oTable = $('#example').dataTable( {
    "sPaginationType": "full_numbers",
    "iDisplayLength": 10,
    "sAjaxSource": "/source/process.php",
    "fnServerData": function ( sSource, aoData, fnCallback ) {
    $.ajax( {
    "dataType": 'json',
    "type": "POST",
    "url": sSource,
    "data": 'txtId=' + $("txtId").val(),
    "success": fnCallback
    } );
    }
    } );

    $("#btnSubmit").click(function(){
    oTable.fnReloadAjax();
    });
    } );






    Enter an id:








    id
    Surname
    Name






    [/code]

    This is the process file:
    [code]
    <?php
    $result="";
    if (empty($_REQUEST["txtId"])) {
    $result = '{"aaData":[["1","Surname1","Name1"]]}';
    }
    else {
    $result = '{"aaData":[["2","Surname2","Name2"]]}';
    }
    print $result;
    ?>
    [/process]

    If I type something in the box it does nothing and when I run it, it just shows result 2. My goal is to have a page with an edit box and search button. When I type something in, it will launch the grid, pass the value to process, and process will act on that value. My goal is to just get a basic sample running.

    Thanks for the comment...
  • allanallan Posts: 63,302Questions: 1Answers: 10,431 Site admin
    Looks like it should work - apart from:

    > $("txtId").val(),

    You want:

    [code]
    $("#txtId").val(),
    [/code]

    !
  • bgdatatblbgdatatbl Posts: 5Questions: 0Answers: 0
    Made this change and it did not fix. Any other ideas?
  • allanallan Posts: 63,302Questions: 1Answers: 10,431 Site admin
    Yup - link us to a JSFiddle or http://live.datatables.net example showing the problem so we (I) can debug it :-)

    Allan
  • bgdatatblbgdatatbl Posts: 5Questions: 0Answers: 0
    Allan, I have not used the above. I have it in codenvy. Can you inbox your email to me and I will ad you. Once we resolve, I will post on log.
  • bgdatatblbgdatatbl Posts: 5Questions: 0Answers: 0
    Alan, I have not heard from you. I would think the question is straight forward. If I have an input box and want to pass this text into an ajax call to use in the data feed, I tried to find this basic example and get it to work. I can old the grid but when it comes to passing data I have no idea on how to get it to work. Please advise...
This discussion has been closed.