Forum


02:05

15/01/2011

Hello together,
i have implementated the simple democode to show a jqGrid with jQuery in a HTML page.
The data type of the grid is json.
i collect the data from a firebird database of a php script.
here the html code:
Code:
...
<div id="pagecontrol-opliste-tabelle">
<table id="table-liste">
</table>
<div id="pager-liste">
</div>
</div>
...
here is the javascript code:
Code:
$(document).ready(function(){
$("#pagecontrol-opliste").tabs();
$("#table-liste").jqGrid({
url: 'Sql.php',
datatype: "json",
colNames: ['Lfd. Nr', 'Kategorie', 'Kunde', 'Stichwort', 'Ersteller', 'Bearbeiter', 'Status'],
colModel: [{
name: 'lfdnr',
index: 'lfdnr',
width: 55
}, {
name: 'kategorie',
index: 'kategorie',
width: 90
}, {
name: 'kunde',
index: 'kunde',
width: 100
}, {
name: 'stichwort',
index: 'stichwort',
width: 80
}, {
name: 'ersteller',
index: 'ersteller',
width: 80
}, {
name: 'bearbeiter',
index: 'bearbeiter',
width: 80
}, {
name: 'status',
index: 'status',
width: 150,
sortable: false
}],
rowNum: 10,
rowList: [10, 20, 30],
pager: '#pager-liste',
sortname: 'lfdnr',
viewrecords: false,
sortorder: 'asc',
caption: "OP Liste",
scrollrows: true
});
$("#table-liste").jqGrid('navGrid', '#pager-liste', {
edit: false,
add: false,
del: false
});
});
here is the php code:
Code:
<?php
$page = $_GET['page']; // get the requested page
$limit = $_GET['rows']; // get how many rows we want to have into the grid
$sidx = $_GET['sidx']; // get index row - i.e. user click to sort
$sord = $_GET['sord']; // get the direction
if(!$sidx) $sidx =1;
// connect to the database
$dbh = ibase_connect ('localhost:C:xampphtdocsOPManagerDatabaseOPManager.GDB', 'SYSDBA', 'masterkey');
$stmt = 'SELECT count(*) FROM OP';
$result = ibase_query($dbh, $stmt);
$row = ibase_fetch_assoc($result);
$count = $row["COUNT"];
//echo $count . "<br>";
if( $count >0 ) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
//$start = 1;
$SQL = "SELECT FIRST $limit SKIP $start LFDNR, KATEGORIE, ERSTDATUM, STICHWORT, ERSTELLER, BEARBEITER, STATUS FROM OP ORDER BY $sidx $sord";
//echo $start . "-" . $limit . "<br>";
//echo $SQL . "<br>";
$result = ibase_query($dbh, $SQL);
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
while($row = ibase_fetch_assoc($result)) {
$responce->rows[$i]['id']=$row[lfdnr];
$responce->rows[$i]['cell']=array($row["LFDNR"],$row["KATEGORIE"],$row["ERSTDATUM"],$row["STICHWORT"],$row["ERSTELLER"],$row["BEARBEITER"],$row["STATUS"]);
$i++;
}
echo json_encode($responce);
ibase_close($dbh);
?>
if i now try to select second or the third or .... for any time the first row was selected and deselected.
in the example on:
http://trirand.com/blog/jqgrid/jqgrid.html
it is possible to select any row and it is possible to search a record.
In my Grid i cant search for a record. After i click on search nothing is happend.
have anyone a idea what can i do?
09:15

Moderators
30/10/2007

Hello,
You do not have the right id
Replace
while($row = ibase_fetch_assoc($result)) {
$responce->rows[$i]['id']=$row[lfdnr];
$responce->rows[$i]
..............................
}
With
while($row = ibase_fetch_assoc($result)) {
$responce->rows[$i]['id']=$row["LFDNR"];
$responce->rows[$i]
..............................
}
Enjoy
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
19:11

15/01/2011

I don't think that was the answer to the question in the title. I'm having the same problem. I'm printing the row ID via
onSelectRow: function(rowId, stat){
console.log("Row id "+rowId+" Status "+stat);
},
And no matter what row I click on, every other click results in the rowId showing up as 1. At the same time row 1 background goes from normal to yellow and back.
Thanks,
Jim.
19:17

15/01/2011

21:02

Moderators
30/10/2007

Hello,
Yes ther is a diffrence I will say big difference
$("#list").addRowData(1,myRow);
This will add data in the grid with rows with same ID = 1.
In order to make correct selection please generate uniquie ID for every row
Kind Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
46 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66