Note that there are some explanatory texts on larger screens.

plurals
  1. POFilling a dataTable with data from another one using jQuery in CodeIgniter
    text
    copied!<p>I use CodeIgniter and I have two dataTables (in two separate views. same js, model and controller files)</p> <p>I can fill the first table with a SELECT query and it works normally.</p> <p>My problem is that I need data (for the query) from the first table (using a click to select which row) to fill the second one. I couldn't make it work yet. I already executed the required SELECT query in phpMyAdmin and it works.</p> <p>controller file</p> <pre><code>function refreshT2(){ $id = $_POST['id']; $id = stripslashes($id); $id = mysql_real_escape_string($id); $this-&gt;load-&gt;model('model'); $data=$this-&gt;model-&gt;getAllById($id); echo json_encode($data); } </code></pre> <p>js file</p> <pre><code>$(document).ready( function () { $("#table1").addClass("started"); $("#table2").addClass("started"); var t1Source = "controller/refreshT1"; var t2Source = "controller/refreshT2"; var oTablet1=$('#table1').dataTable({ "sScrollX": "100%", "sPaginationType":"full_numbers", "bJQueryUI":true, "sDom": 'R&lt;"H"lfr&gt;t&lt;"F"ip&gt;', "bDeferRender": true, "bProcessing": true, "bServerSide": true, "aaSorting": [[ 0, "desc" ]], "sAjaxSource": ft1Source }); $("#table1 tbody").click(function(event) { var iPos=oTablet1.fnGetPosition(event.target.parentNode); var aData=oTablet1.fnGetData(iPos); var id=aData[2]; $('input[name=id]').val(id); /* When I click on the first dataTable the field 'id' is filled properly */ var oTableft2 = $('#table2').dataTable({ "sScrollX": "100%", "sPaginationType":"full_numbers", "bJQueryUI":true, "sDom": 'R&lt;"H"lfr&gt;t&lt;"F"ip&gt;', "bDeferRender": true, "bProcessing": true, "bRetrieve": true, "bDestroy": true, "bServerSide": true, "aaSorting": [[ 0, "desc" ]], "sAjaxSource": t2Source }); } ); } </code></pre> <p>If I need to provide more information/code please tell me.</p> <p>Thank you for your time.</p> <p>EDIT: when I switch <code>$id = $_POST['id'];</code> with a real value it works. How can I retrieve this data? </p> <p>I don't want to use a "button+action" solution. If it works inside the js I won't need any send/receive method. what I need is how to pass a parameter to the second table.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload