jqGrid pager only displaying one page of results - javascript

My jqGrid displays correctly but it only shows one page of results. What ever I set rowNum to, that is all the results it will ever display even though right next to it it says it is displaying 10 out of 181 results. Is there some parameter I have to tweak to get the pager to allow me to actually page?
Thanks,
Kyle
jQuery("#corporateavgmap").jqGrid({
url:'monthly_corp_rates.jsp?'+dataString,
datatype: "json",
mtype:'POST',
colNames:['','USD', 'GBP', 'EUR','CAD','THB','HKD', 'MYR', 'JPY','AUD','IDR','KRW' ],
colModel:[
{name:'',index:'fromCurr', width:55, jsonmap:"fromCurr" },
{name:'USD', width:90, jsonmap:"toUSD"},
{name:'GBP', width:100, jsonmap:"toGBP"},
{name:'EUR', width:80, align:"right", jsonmap:"toEUR"},
{name:'CAD', width:80, align:"right", jsonmap:"toCAD"},
{name:'THB', width:80, align:"right", jsonmap:"toTHB"},
{name:'HKD', width:80, align:"right", jsonmap:"toHKD"},
{name:'MYR', width:80, align:"right", jsonmap:"toMYR"},
{name:'JPY', width:80, align:"right", jsonmap:"toJPY"},
{name:'AUD', width:80, align:"right", jsonmap:"toAUD"},
{name:'IDR', width:80, align:"right", jsonmap:"toIDR"},
{name:'KRW', width:80, align:"right", jsonmap:"toKRW"}
],
rowNum:10,
rowList:[10,20,30],
pager: '#pjmap2avg',
sortname: 'tradeDT',
viewrecords: true,
sortorder: "desc",
jsonReader: {
root : "corporateavgrate",
repeatitems : false,
id: "fromCurr"
},
caption: "Average Corporate Rates For: "+month+"-"+year,
height: '100%',
reloadAfterEdit: true,
reloadAfterSubmit: true,
reloadonce: false,
autowidth:true,
viewrecords: true,
gridview: true
});
alert("hello");
jQuery("#corporateavgmap").jqGrid('navGrid','#pjmap2avg',{edit:false,add:false,del:false,refresh:true}).
jqGrid('navButtonAdd',"#pjmap2avg",{caption:"Export to Excel",buttonicon:"", onClickButton: corpAVGMonthlyRatesTableToExcel , position:"last",title:"",cursor:"pointer"});

Related

jqGrid - always select first row using setSelection is not working

I am populating jqgrid with data on page load and trying to set the first row always selected in but, for some reason it is not working.
Fiddle: https://jsfiddle.net/99x50s2s/116/
var customGrid = jQuery("#sg1");
customGrid.jqGrid({
datatype: "local",
gridview: true,
loadonce: true,
shrinkToFit: false,
autoencode: true,
height: 'auto',
viewrecords: true,
sortorder: "desc",
scrollrows: true,
loadui: 'disable',
idPrefix: "cg_",
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:60, sorttype:"int"},
{name:'invdate',index:'invdate', width:90, sorttype:"date"},
{name:'name',index:'name', width:80},
{name:'amount',index:'amount', width:80, align:"right",sorttype:"float"},
{name:'tax',index:'tax', width:80, align:"right",sorttype:"float"},
{name:'total',index:'total', width:80,align:"right",sorttype:"float"},
{name:'note',index:'note', width:150, sortable:false}
],
caption: "Test Grid"
});
var mydata = [
{id:"1",invdate:"2007-10-01",name:"test 1234567890123456789",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
{id:"2",invdate:"2007-10-02",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"}
];
customGrid[0].addJSONData(mydata);
//set the first row always selected on initial load
customGrid.jqGrid('setSelection', 1);
Expectation:
First row should be selected.
Am I missing anything? Any suggestion is appreciated.
Please remove following setting:
idPrefix: "cg_",
You can try my version. Please make sure you have jquery-ui library loaded properly. When the idPrefix is set then it can't set the class called ui-state-highlight to the row using just ID.
var jgrid = $("#jqGrid").jqGrid({
datatype: "json",
gridview: true,
loadonce: true,
shrinkToFit: false,
autoencode: true,
viewrecords: true,
sortorder: "desc",
scrollrows: true,
loadui: 'disable',
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:60, sorttype:"int"},
{name:'invdate',index:'invdate', width:90, sorttype:"date"},
{name:'name',index:'name', width:80},
{name:'amount',index:'amount', width:80, align:"right",sorttype:"float"},
{name:'tax',index:'tax', width:80, align:"right",sorttype:"float"},
{name:'total',index:'total', width:80,align:"right",sorttype:"float"},
{name:'note',index:'note', width:150, sortable:false}
],
width: 1280,
height: 'auto',
rowNum: 150,
caption: "Test Grid"
});
var mydata = [
{id:"1",invdate:"2007-10-01",name:"test 1234567890123456789",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
{id:"2",invdate:"2007-10-02",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"}
];
jgrid[0].addJSONData(mydata);
jgrid.jqGrid('setSelection', 1);
As I have set the idPrefix in my jqGrid. I have updated the setSelection as
customGrid.jqGrid('setSelection', 'cg_1'); and the first row selection works now.

jqgrid - beforeSearch and afterSearch function are not triggered

I am trying to display a progress bar when user tries to filter data in jqgrid. But, the beforeSearch and afterSearch functions are not triggered.
I tried to follow the documentation: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:toolbar_searching but, not sure what I am missing...
Here is the fiddler: http://jsfiddle.net/14f3Lpnk/1/
<table id="list"></table>
<div id="pager"></div>
var mydata = [
{id:"1",invdate:"2010-05-24",name:"test",note:"note",tax:"10.00",total:"2111.00"} ,
{id:"2",invdate:"2010-05-25",name:"test2",note:"note2",tax:"20.00",total:"320.00"},
{id:"3",invdate:"2007-09-01",name:"test3",note:"note3",tax:"30.00",total:"430.00"},
{id:"4",invdate:"2007-10-04",name:"blah",note:"stuff",tax:"10.00",total:"210.00"}
];
jQuery("#list").jqGrid({
data: mydata,
datatype: "local",
height: 150,
rowNum: 10,
ignoreCase: true,
rowList: [10,20,30],
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:60, sorttype:"int"},
{name:'invdate',index:'invdate', width:90, sorttype:"date", formatter:"date"},
{name:'name',index:'name', width:100},
{name:'amount',index:'amount', width:80, align:"right",sorttype:"float", formatter:"number"},
{name:'tax',index:'tax', width:80, align:"right",sorttype:"float"},
{name:'total',index:'total', width:80,align:"right",sorttype:"float"},
{name:'note',index:'note', width:150, sortable:false}
],
pager: "#pager",
viewrecords: true,
autowidth: true,
height: 'auto',
caption: "Test Grid",
beforeSearch: function () {
alert('Filter Started');
},
afterSearch: function () {
alert('Filter Complete');
}
}).jqGrid('filterToolbar', { stringResult: true, searchOnEnter: true, defaultSearch: "cn" });
Any help is appreciated.
beforeSearch and afterSearch are callback functions of filterToolbar method and not the grid itself. So you should use there in the following way
.jqGrid('filterToolbar', {
stringResult: true,
searchOnEnter: true,
defaultSearch: "cn",
beforeSearch: function () {
alert('Filter Started');
},
afterSearch: function () {
alert('Filter Complete');
}
});
See the modified demo http://jsfiddle.net/OlegKi/14f3Lpnk/2/

Displaying bootstrap icon along with jqgrid caption text

I am trying to display twitter bootstrap icon in the jqgrid caption section but, the icon is not displaying. Here is the fiddler: https://jsfiddle.net/99x50s2s/31/
Code Tried:
jQuery("#sg1").jqGrid({
datatype: "local",
gridview: true,
loadonce: true,
shrinkToFit: false,
autoencode: true,
height: 'auto',
viewrecords: true,
sortorder: "desc",
scrollrows: true,
loadui: 'disable',
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:60, sorttype:"int"},
{name:'invdate',index:'invdate', width:90, sorttype:"date"},
{name:'name',index:'name', width:100},
{name:'amount',index:'amount', width:80, align:"right",sorttype:"float"},
{name:'tax',index:'tax', width:80, align:"right",sorttype:"float"},
{name:'total',index:'total', width:80,align:"right",sorttype:"float"},
{name:'note',index:'note', width:150, sortable:false}
],
caption: "<i class'glyphicon glyphicon-alert'></i> Pending"
});
Current Output:
Expected:
Am I missing anything? Is it possible to display bootstrap icon in jqgrid caption? Please suggest.
It's a typo. You are missing the = :
caption: "<i class'glyphicon glyphicon-alert'></i> Pending"
should be:
caption: "<i class='glyphicon glyphicon-alert'></i> Pending"
https://jsfiddle.net/99x50s2s/33/

jqGrid - Custom button in nav bar added multiples times

I've added a custom button on my nav bar:
function myFunc(){
$("#grid").jqGrid({
datatype: 'json',
url: 'arquivo.jsp',
jsonReader: {repeatitems: false, root: 'root'},
pager: '#paginado',
rowNum: 10,
autoencode: true,
rowList: [10,20,30],
emptyrecords: "Não há registros.",
recordtext: "Registros {0} - {1} de {2}",
loadtext: "Carregando...",
pgtext: "Página {0} de {1}",
height: 250,
width: 700,
colNames:['Código','Nome', 'Ativo', 'Data Inclusão','Login','Senha','Confirma Senha','Email','Grupos'],
colModel:[
{name:'codigo', width:80, sorttype:"int", editable: true, editrules: { edithidden: true }},
{name:'nome', width:120, editable: true, editrules:{required:true}},
{name:'ativo', width:80, gridview: true, editable: true, edittype:'select', editoptions:{value:{1:'Sim',2:'Não'}}, editrules:{required:true}},
{name:'dataInclusao', width:120, sorttype:"date", datefmt: 'd/M/Y', editable: true, editrules:{required:true, date:true}, editoptions: { dataInit: function(el) { setTimeout(function() { $(el).datepicker({ dateFormat: 'dd/mm/yy' }).val(); }, 200); }}},
{name:'login', width:80, sortable:true, editable: true, editrules:{required:true}},
{name:'senha', width:80, sortable:true, editable: true, hidden:true, edittype:'password', editrules:{edithidden:true, required:true, custom:true, custom_func:validaSenha}},
{name:'confirmaSenha', width:80, sortable:true, editable: true, hidden:true, edittype:'password', editrules:{edithidden:true, required:true}},
{name:'email', width:150, sortable:true, editable: true, editrules:{required:true, email:true}}
],
multiselect: true,
viewrecords: true,
editurl:"data?edit=true",
caption: "Usuários"}
);
$("#grid").jqGrid('navGrid','#paginado',{},
{edit:true,url:"teste?acao=edit",closeAfterEdit:true,reloadAfterSubmit:true,
beforeShowForm: function(form) {
$('#tr_codigo', form).hide();
},
onClickSubmit: function(params, postdata) {
validaSenha();
}
},
{add:true,url:"teste?acao=teste",closeAfterAdd:true,reloadAfterSubmit:true,
beforeShowForm: function(form) {
$('#tr_codigo', form).hide();
},
onClickSubmit: function(params, postdata) {
validaSenha();
}
},
{del:true,reloadAfterSubmit:true,
onclickSubmit: function(url, postdata){
url.url = 'teste?acao=del';
return {codigo: $('#grid').getCell(postdata, 'codigo')};
}
},
{search:true},
{refresh:true}
).navButtonAdd('#paginado',{
caption:"",
buttonicon:"ui-icon-suitcase",
onClickButton: function(){
var dados = $("#grid").jqGrid('getGridParam','selrow');
},
position:"last"
});
};
but everytime I click on the page that shows my grid, a new button is added as you can see in this image:
I don't know if my .jsp can be bringing on this problem but I definitely can't find where the problem is. Hope you guys can help me
Thanks in advance,
Lucas.
I solved the problem using $('#grid').jqGrid('GridUnload');
There is another thread which talks about same issue. In the newer version the syntax got changed. Might help someone. Please refer here
$.jgrid.gridUnload("#jqGridId");

Adding filter to each column of jqgrid

I have a jqgrid that shows details of employees and i would like to add a filter in each column using which a user can type in company name and the grid shows all the employee rows that matches that filter in the grid.
Googled alot but no success. Any refrence examples/link will help.
You should use filterToolbar option when you type the name of test case in the text box you data will fiter through the records, here is the code and working example demo
var mydata = [
{id:"1",invdate:"2010-05-24",name:"test",note:"note",tax:"10.00",total:"2111.00"} ,
{id:"2",invdate:"2010-05-25",name:"test2",note:"note2",tax:"20.00",total:"320.00"},
{id:"3",invdate:"2007-09-01",name:"test3",note:"note3",tax:"30.00",total:"430.00"},
{id:"4",invdate:"2007-10-04",name:"blah",note:"stuff",tax:"10.00",total:"210.00"},
];
jQuery("#list").jqGrid({
data: mydata,
datatype: "local",
height: 150,
rowNum: 10,
rowList: [10,20,30],
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:60, sorttype:"int"},
{name:'invdate',index:'invdate', width:90, sorttype:"date", formatter:"date"},
{name:'name',index:'name', width:100},
{name:'amount',index:'amount', width:80, align:"right",sorttype:"float", formatter:"number"},
{name:'tax',index:'tax', width:80, align:"right",sorttype:"float"},
{name:'total',index:'total', width:80,align:"right",sorttype:"float"},
{name:'note',index:'note', width:150, sortable:false}
],
pager: "#pager",
viewrecords: true,
autowidth: true,
height: 'auto',
caption: "Test Grid"
});
jQuery("#list").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: "cn" });
<table id="list"></table>
<div id="pager"></div>

Categories

Resources