Title: [SOLVED] Master / Detail pass parameter on click
Post by: MFS on May 12, 2016, 05:37:32 AM
Hello there. I have one problem. On one page I put two datagrids. I need that on click in first one pass params to second one.In my case I want to on row click pass ID ( in my case that i fiels Sifra) of that row to second grid and reload that grid with that new params. Can you tell me how to do that? Some sample, please. Thanks.
(http://s32.postimg.org/661psvef9/Capture.png)
Title: Re: Master / Detail pass parameter on click
Post by: stworthy on May 12, 2016, 04:49:47 PM
When click on a row, the 'onClickRow' event fires. You can retrieve the clicked row data and call 'load' method on the second datagrid to load its data. $('#dg1').datagrid({ onClickRow: function(index,row){ $('#dg2').datagrid('load', { id: row.id }); } })
Title: Re: Master / Detail pass parameter on click
Post by: MFS on May 12, 2016, 11:21:44 PM
This is not working on my code. This is page (part of code): <script> $('#grdRadnaGrupaSastanak').datagrid( { onClickRow: function(index,row) { $('#grdSRadnaGrupaSastanakPrisutni').datagrid('load', { id: row.RadnaGrupaSastanakID }); } }) </script> <!-- --------------------------------------------------- CSS FORME ZA UNOS KRAJ -------------------------- --> <?php include 'PHPLib/PrikaziMeni.php'; ?> <!-- ----------------------------------------------------------------------------------------------------- --> <div class="grid_10"> <div class="box round first"> <h2>Sastanci radnih grupa</h2> <div class="block"> <div id="gridpozicija"> <!-- -------------------------------------------- GRID DETALJI I FORMA ZA UNOS --------------------------- --> <!-- Grid forma --> <table id="grdRadnaGrupaSastanak" title="" class="easyui-datagrid" style="auto;height:300px" url="dsrRadnaGrupaSastanak.php" toolbar="#toolbar" pagination="true" rownumbers="true" fitColumns="true" singleSelect="true" > <thead> <tr> <th field="RadnaGrupaSastanakID" width="8">Šifra</th> <th field="SRadnaGrupa" width="8">Šifra</th> <th field="SRadnaGrupaNazivX" width="60" >Naziv</th> <th field="DatumSastankaX" width="40" >Datum sastanka</th> <th field="Razlog" width="100" >Razlog</th> <th field="Zakljucak" width="100" >Zaključak</th> </tr> </thead> </table> </br> <div class="easyui-tabs" style="auto;height:350px"> <div title="Prisutni" style="padding:10px;"> <table id="grdSRadnaGrupaSastanakPrisutni" title="" class="easyui-datagrid" style="auto;height:300px" url="dsrRadnaGrupaSastanakPrisutni.php" toolbar="#toolbarstavke" pagination="true" rownumbers="true" fitColumns="true" singleSelect="true" > <thead> <tr> <th field="RadnaGrupaSastanakID" width="10">Šifra</th> <th field="SysKorisnikID" width="10" >Korisnik</th> <th field="SysKorisnikImeX" width="200" >Korisnik ime</th> </tr> </thead> </table> </div> </div>
This is code of data source for first (master) grid: <?php $page = isset($_POST['page']) ? intval($_POST['page']) : 1; $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10; $offset = ($page-1)*$rows; $result = array();
include 'Konekcija/Konekcija.php';
$msqRadnaGrupaSastanak = "{call ProEZ.spRadnaGrupaSastanak}"; $msqRadnaGrupaSastanakPolja = sqlsrv_query( $konekcija, $msqRadnaGrupaSastanak); $row = sqlsrv_fetch_array($msqRadnaGrupaSastanakPolja); $result["total"] = $row[0]; $msqRadnaGrupaSastanakPolja = sqlsrv_query( $konekcija, $msqRadnaGrupaSastanak); $items = array(); while($row = sqlsrv_fetch_object($msqRadnaGrupaSastanakPolja)){ array_push($items, $row); } $result["rows"] = $items;
echo json_encode($result); ?>
This is code of data source for second (detail) grid: <?php $page = isset($_POST['page']) ? intval($_POST['page']) : 1; $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10; $offset = ($page-1)*$rows; $result = array(); include 'Konekcija/Konekcija.php'; $RadnaGrupaSastanakID = htmlspecialchars($_REQUEST['RadnaGrupaSastanakID']);
$parametri = array( array($RadnaGrupaSastanakID, SQLSRV_PARAM_IN) ); $msqRadnaGrupaSastanakPrisutni = "{call ProEZ.spRadnaGrupaSastanakPrisutni (?)}"; $msqRadnaGrupaSastanakPrisutniPolja = sqlsrv_query( $konekcija, $msqRadnaGrupaSastanakPrisutni,$parametri); $row = sqlsrv_fetch_array($msqRadnaGrupaSastanakPrisutniPolja); $result["total"] = $row[0]; $msqRadnaGrupaSastanakPrisutniPolja = sqlsrv_query( $konekcija, $msqRadnaGrupaSastanakPrisutni,$parametri); $items = array(); while($row = sqlsrv_fetch_object($msqRadnaGrupaSastanakPrisutniPolja)){ array_push($items, $row); } $result["rows"] = $items;
echo json_encode($result); ?>
I checked storage procedures, and they are ok.Works fine.In firsta ( master ) grid I have data, but when I click on row, nothing is happening. Any idea or solution?
Title: Re: Master / Detail pass parameter on click
Post by: stworthy on May 13, 2016, 04:00:22 PM
In your php code, you receive the 'RadnaGrupaSastanakID' parameter, so the js code should be: <script> $(function(){ $('#grdRadnaGrupaSastanak').datagrid( { onClickRow: function(index,row) { $('#grdSRadnaGrupaSastanakPrisutni').datagrid('load', { RadnaGrupaSastanakID: row.RadnaGrupaSastanakID }); } }) }) </script>
Title: Re: Master / Detail pass parameter on click
Post by: MFS on May 15, 2016, 11:27:17 PM
That is ok. Now its work. Thanks.
|