Forum


10:49

14/11/2008

Hi.. i´ve been trying to use jqgrid with Struts 2 for the last 2 weeks and
finally succeded! I´m using json for dealing the data.
I can now edit data and remove data but for search i had to implement my own method passing the 3 values searchField,searchOper,searchString
because the search from the grid wasn´t working( actually i couldnt figure out if i still needed to implement something like i did or it was already suppposed to do search if the data was already loaded).
Now the 2 problems :
the first is the sorting that is not working! When you click it is sorting randomly and diffent from the previous one at every single click.
the second one is the reset button from the search. it is not reseting the grid. I´ve already checked that when click on the reset button the _search param becames false but still shows the value from the search.
Here´s the method that i get the data from the database:
public String getJSON(){
List<Setor> setortemp = null;
setor = new HashSet<Setor>();
if(searchField != null){
setortemp = s.novaBusca(searchField, searchOper, searchString);
}
else{
setortemp = s.findAll();
}
long max = Math.min(((page - 1)* rows) + rows, setortemp.size());
for (int i = (int) ((page - 1)* rows); i < max; i++) {
setor.add(setortemp.get(i));
}
records = setortemp.size();
total = Math.round(setortemp.size() / rows) + 1;
return "json";
}
And here is the grid:
jQuery(document).ready(function(){
jQuery("#list2").jqGrid({
url:'FetchJSON.action?nd='+new Date().getTime(),
datatype: "json",
colNames:['Id', 'Setor'],
colModel:[
{name:'idsetor',index:'idsetor', width:50, editoptions:{readonly:true,size:10}},
{name:'nomesetor',index:'nomesetor', width:75, editable:true, editoptions:{size:10}},
],
pager: jQuery('#pager2'),
rowNum:10,
rowList:[10,20,30],
imgpath: 'themes/sand/images',
sortname: 'idsetor',
viewrecords: true,
caption: "Teste",
width : 500,
height : "100%",
loadtext : "Carregando",
recordtext : "registros",
editurl: 'saveSetor.action',
jsonReader: { repeatitems : false, id : "idsetor", root:"setor"}
}).navGrid('#pager2',
{refresh: true, edit: true, add: true, del: true,search: true}, //options
{height:100, reloadAfterSubmit:false, url:"saveSetor.action"}, // edit options
{height:100, reloadAfterSubmit:true, url:"saveSetor"}, // add options
{reloadAfterSubmit:true, url:"RemoveJSON.action"}, // del options
{} // search options
);
});
Thanks in advance.
05:47

Moderators
30/10/2007

Hello,
1. For the sorting - check your server side code. In this case jqGrid
accept the data from server and there is nothing to do more.
2. Use this logic server side:
if( _search =='true') {
// perform the serch here
} else {
// reset the serch values here
// and return not searched data
}
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.
07:24

14/11/2008

Hi Tony, thanks for your answer !
For the second problem it worked perfectly! No problems anymore!
Now , for the first you said that i should check the server side code !
By that you meant the way i get the data from the database?
If so then the problem is here ?
long max = Math.min(((page - 1)* rows) + rows, setortemp.size());
for (int i = (int) ((page - 1)* rows); i < max; i++) {
setor.add(setortemp.get(i));
}
records = setortemp.size();
total = Math.round(setortemp.size() / rows) + 1;
It´s weird because the paging is working just fine. Any other idea of how i can do this?
Thanks
06:53

Moderators
30/10/2007

Hello,
Also obtain the sort name and sort order server side and include this in the
SQL query. See docs how to do that and which parameters to use.
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.
07:16

14/11/2008

Hi Tony,
Before i tried you suggestion i tried to print the list and noticed that it was receving the data from database perfectly ordered. What i mean is that theres something confusing the way that the jqgrid is printing because if the list is ordered before it shows the grid, why is not after the grid is printed?
Anyway, I´ve tried without success to pass the values :
sortorder = "desc";
sortname = "nomesetor";
and add it to the method wich makes the query to get the data from database.This didn´t work, but i´ve noticed that the values are correctly passed via the json (noticed via firebug).
Any other idea?
04:13

Moderators
30/10/2007

Hello,
As of the docs parameters passed to the server are:
page - the requested page
rows - requested rows
sidx - the index or name of the sorted column from colModel
sord - the order - asc or desc
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:
60 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