I am trying to catch the moment when the grid is reloaded ( grid.trigger('reloadGrid') ) so that I can scroll it to the position needed. What happens at the moment is when I scroll it down it fires the event on every ajax call (like load more rows).
I tried using different events, which one is the right?
The code is simple initialization, nothing special here
jQuery("#filtergrid").jqGrid({
scroll:true,
scrollrows:true,
datatype: 'json',
url: '/bo/filter/index.php?func=get-list',
mtype: 'POST',
colNames:[
'ID',
'Title',
'Domain',
'Random',
'Men',
'Women',
'Snails',
'Min Age',
'Max Age',
'Read Days',
'Click Days',
'Join Days',
'Master',
'<img src="/assets/duplicate.gif">'
],
colModel :[
{name:'flt_id', index:'flt_id', width:50, key:true, search: false, key: true, fixed: true},
{name:'flt_title', index:'flt_title', width:215, fixed: true, formatter: formatName},
{name:'dmn_name', index:'dmn_name', width:220, fixed: true},
{name:'is_random', index:'is_random', search: false, width:50, fixed: true, formatter: stsFormatter, align: 'center', sortable: false},
{name:'is_man', index:'is_man', search: false, width:50, fixed: true, formatter: stsFormatter, align: 'center', sortable: false},
{name:'is_woman', index:'is_woman', search: false, width:50, fixed: true, formatter: stsFormatter, align: 'center', sortable: false},
{name:'is_snals', index:'is_snals', search: false, width:50, fixed: true, formatter: stsFormatter, align: 'center', sortable: false},
{name:'min_age', index:'min_age', search: false, width:53, fixed: true, align: 'center', sortable: false},
{name:'max_age', index:'max_age', search: false, width:58, fixed: true, align: 'center', sortable: false},
{name:'read_days', index:'read_days', width:60, fixed: true, search: false, formatter: numFormatter, align: 'center', sortable: false},
{name:'click_days', index:'click_days', width: 60, fixed: true, search: false, formatter: numFormatter, align: 'center', sortable: false},
{name:'join_days', index:'join_days', width:58, fixed: true, search: false, formatter: numFormatter, align: 'center', sortable: false},
{name:'flt_master', index:'flt_master', width:50, fixed: true, search: false, formatter: stsMasterFormatter, align: 'center', sortable: false},
{name:'editlink', index:'editlink', width:20, fixed: true, formatter: formatEditImg, search: false}
],
lastSel: null,
pager: '#pager',
rowNum: 150,
rowList: [150],
sortname: 'dmn_name',
height: 320,
autowidth:false,
gridview: true,
sortorder: 'asc',
viewrecords: true,
caption: 'Filters',
footerrow : false,
userDataOnFooter : false,
altRows : true,
//postData : '',
multipleSearch:true,
jsonReader : { repeatitems: false },
pager: '#pager',
width: 1130, //shrinkToFit: true
gridComplete: function(){
jQuery("#filtergrid").closest(".ui-jqgrid-bdiv").scrollTop(scrollPosition)
}
});
Thanks!
Instead of gridComplete use loadComplete. Look at this thread for difference between the two events
Grid Complete vs Load Complete
I try to use two different jqgrid on the same page with the mvc application, tables are using diferent URL to load data and diferent names. It's possible use multiple jqgrid on same page!?!?
Thanks in advance
UPDATED: First thanks for the quick response
The problem continue after I've change the ids as you told me!
Here is my code:
Javasrcipt :
First Grid :
jQuery("#listMedicosTODO").jqGrid({
url: '/Medico/LoadToDoMedicos/',
datatype: 'json',
mtype: 'GET',
colNames: ['Cod.', 'Titulo', 'Estado', 'Ultima Actualização'],
colModel: [
{ name: 'CodRelatorio', index: 'CodRelatorio', width: 50, align: 'center', hidden: true, sortable: false },
{ name: 'TituloRelatorio', index: 'TituloRelatorio', width: 100, align: 'center', sortable: true },
{ name: 'EstadoRelatorio', index: 'EstadoRelatorio', width: 100, align: 'left', sortable: false },
{ name: 'DataUltimaActualizao', index: 'DataUltimaActualizao', width: 100, align: 'left', hidden: false, sortable: false }
],
pager: jQuery('#pager1'),
rowNum: 50,
rowList: [50],
sortname: 'Id',
sortorder: "asc",
viewrecords: true,
imgpath: '/scripts/themes/steel/images',
caption: 'Tarefas Pendentes Médicos',
onSelectRow: function (id) {
var data = $("#listMedicosTODO").getRowData(id);
alert("select row " + data.CodRelatorio);
},
loadComplete: function (data) {
alert("Load Complete");
//$('#list').setGridParam({ url: '/PesquisarRelatorios/GetGridData/' });
},
gridComplete: function () { alert("Grid Complete"); },
beforeRequest: function () { },
viewrecords: true,
autowidth: true,
autoheight: true
}).navGrid(pager, { edit: false, add: true, del: true, refresh: true, search: false });
Second Grid :
jQuery("#listaAssistentesTODO").jqGrid({
url: '/Medico/LoadToDoAssistentes/',
datatype: 'json',
mtype: 'GET',
colNames: ['Cod.', 'Titulo', 'Assistente', 'Estado', 'Ultima Actualização'],
colModel: [
{ name: 'CodRelatorio', index: 'CodRelatorio', width: 50, align: 'center', hidden: true, sortable: false },
{ name: 'TituloRelatorio', index: 'TituloRelatorio', width: 100, align: 'center', sortable: true },
{ name: 'Assistente', index: 'Assistente', width: 100, align: 'center', sortable: false },
{ name: 'EstadoRelatorio', index: 'EstadoRelatorio', width: 100, align: 'left', sortable: false },
{ name: 'DataUltimaActualizao', index: 'DataUltimaActualizao', width: 100, align: 'left', hidden: false, sortable: false }
],
pager: jQuery('#page2'),
rowNum: 50,
rowList: [50],
sortname: 'CodRelatorio',
sortorder: "asc",
viewrecords: true,
imgpath: '/scripts/themes/steel/images',
caption: 'Tarefas Pendentes Assistentes',
onSelectRow: function (id) {
var data = $("#listaAssistentesTODO").getRowData(id);
alert("select row " + data.CodRelatorio);
},
loadComplete: function (data) {
alert("Load Complete");
//$('#list').setGridParam({ url: '/PesquisarRelatorios/GetGridData/' });
},
gridComplete: function () { alert("Grid Complet"); },
beforeRequest: function () { },
viewrecords: true,
autowidth: true,
autoheight: true
}).navGrid(pager, { edit: false, add: true, del: true, refresh: true, search: false });
Server endpoint :
1º
if(list != null)
{
int pageIndex = Convert.ToInt32(page) - 1;
int pageSize = rows;
int totalRecords = list.Count ;
var totalPages = (int)Math.Ceiling(totalRecords / (float)pageSize);
var jsonData = new
{
total = totalPages,
page,
records = totalRecords,
rows = (from item in list
select new
{
i ="a" + item.CodRelatorio,
cell = new[]
{
item.CodRelatorio ,
item.TituloRelatorio,
item.Assistente ,
"Em Elaboração",
item.DataUltimaActualizao
}
}).ToArray()
};
return Json(jsonData,JsonRequestBehavior.AllowGet);
}
2º end point
if (list != null)
{
int pageIndex = Convert.ToInt32(page) - 1;
int pageSize = rows;
int totalRecords = list.Count;
var totalPages = (int)Math.Ceiling(totalRecords / (float)pageSize);
var jsonData = new
{
total = totalPages,
page,
records = totalRecords,
rows = (from item in list
select new
{
i = "b"+ item.CodRelatorio,
cell = new[]
{
item.CodRelatorio ,
item.TituloRelatorio,
"Em Elaboração",
item.DataUltimaActualizao
}
}).ToArray()
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
This code contain your recomendations
Thanks
It is possible to use more as one jqGrid on one page. The most important thing which you should know is that ids which you posted from the server must be different in both grids. For example if you need for the first grid the id=1234 and the same for the second grid you can use "a1234" for the first grid and "b1234" for the second one.
If you will continue to have problems with two grids you should post the definition (JavaScript code) of the both grids and the test JSON or XML data with which you have problems.
UPDATED: Your main error is that you don't set and id on the server side. Instead of that you set i property which is unknown and which will be ignored. If no id is defined jqGrd try to use integers: "1", "2", ... values as the ids. Such "id-fix" works in case of one grid on the page, but not with two grids.
So you have to change i ="a" + item.CodRelatorio and i = "b"+ item.CodRelatorio to id ="a" + item.CodRelatorio and id = "b"+ item.CodRelatorio.
To tell the trust in the demo example posted by Phil Haack was the same writing error, but it is fixed at Mar 06, 2011 (see the comments on the page).
Another small changes which you should do are
remove deprecated jqGrid parameter imgpath. It is not used since many years.
instead of unknown parameters autowidth: true and autoheight: true you probably wanted to use height:'auto'.
it is better to use pager:'#page1' and pager:'#page2' instead of pager: '#page1' and pager: '#page2'.
The first grid don't has the column with the name 'Id'. So you should replace sortname: 'Id' jqGrid option to for example sortname: 'CodRelatorio'.
I recommend you to read the "UPDATED" part of the answer. You can download the example from the answer and use it as the template for your application.
Yes, we can use multiple Jqgrid in a single page, but have to give different Jqgrid IDs.
See below code. The working Example,
jQuery(document).ready(function () {
$("#datagrid").jqGrid({ //////////// 1st Grid
url: "service url",
//url: "service url",
type: "GET",
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
datatype: "json",
//colNames:['Id','MID','Status','DocNo','VendorID','InvoiceNo','VendorName','Amount','Type','DocDate','DueDate','ClDoc','Texxt','UserName','Currency','ConCode','Region','Stat','Comb','Comments'],
colNames:['Id','MID','Status','VendorID','VendorName','InvoiceNo','DocDate','Amount','DocNo','Type','DueDate','ClDoc','Text','UserName','Currency','ConCode','Region','Stat','Process','Comb','Comments'],
colModel:[
{name:'id',index:'id', width:50,sortable:true},
{name:'mid',index:'mid', width:50, sortable:true},
{name:'status',index:'status', width:70, sortable:true},
{name:'vendorid',index:'vendorid', width:90, sortable:false,align:"left"},
{name:'vendorname',index:'vendorname', width:170, sortable:false,align:"left"},
{name:'invoiceno',index:'invoiceno', width:130, sortable:false,align:"left"},
{name:'docdate',index:'docdate', width:100, sortable:false},
{name:'amount',index:'amount', width:80, sortable:false,align:"Right"},
{name:'docno',index:'docno', width:100, sortable:false},
{name:'typee',index:'typee', width:50, sortable:false},
{name:'duedate',index:'duedate', width:100, sortable:false},
{name:'cldoc',index:'cldoc', width:80, sortable:false},
{name:'text',index:'texxt', width:70, sortable:false},
{name:'username',index:'username', width:100, sortable:false},
{name:'currency',index:'currency', width:80, sortable:false},
{name:'concode',index:'concode', width:80, sortable:false},
{name:'region',index:'region', width:70, sortable:false},
{name:'stat',index:'stat', width:60, sortable:false},
{name:'process',index:'process', width:60, sortable:false},
{name:'combination',index:'combination', width:60, sortable:true},
{name:'comments',index:'comments', width:150, height:20, edittype:'textarea', sortable:false, editable: true,
editoptions: {disabled: false, size:50, resizable:true}}
],
viewrecords: true
});
$("#datagrid1").jqGrid({ ///////////////2nd Grid
url: "service url",
type: "GET",
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
datatype: "json",
//colNames:['Id','MID','Status','DocNo','VendorID','InvoiceNo','VendorName','Amount','Type','DocDate','DueDate','ClDoc','Texxt','UserName','Currency','ConCode','Region','Stat','Comb','Comments'],
colNames:['Id','MID','Status','VendorID','VendorName','InvoiceNo','DocDate','Amount','DocNo','Type','DueDate','ClDoc','Text','UserName','Currency','ConCode','Region','Stat','Process','Comb','Comments'],
colModel:[
{name:'id',index:'id', width:50,sortable:true},
{name:'mid',index:'mid', width:50, sortable:true},
{name:'status',index:'status', width:70, sortable:true},
{name:'vendorid',index:'vendorid', width:90, sortable:false,align:"left"},
{name:'vendorname',index:'vendorname', width:170, sortable:false,align:"left"},
{name:'invoiceno',index:'invoiceno', width:130, sortable:false,align:"left"},
{name:'docdate',index:'docdate', width:100, sortable:false},
{name:'amount',index:'amount', width:80, sortable:false,align:"Right" },
{name:'docno',index:'docno', width:100, sortable:false},
{name:'typee',index:'typee', width:50, sortable:false},
{name:'duedate',index:'duedate', width:100, sortable:false},
{name:'cldoc',index:'cldoc', width:80, sortable:false},
{name:'text',index:'texxt', width:70, sortable:false},
{name:'username',index:'username', width:100, sortable:false},
{name:'currency',index:'currency', width:80, sortable:false},
{name:'concode',index:'concode', width:80, sortable:false},
{name:'region',index:'region', width:70, sortable:false},
{name:'stat',index:'stat', width:60, sortable:false},
{name:'process',index:'process', width:60, sortable:false},
{name:'combination',index:'combination', width:60, sortable:true},
{name:'comments',index:'comments', width:150, edittype:'textarea', sortable:false, editable: true,
editoptions: {disabled: false, size:50, resizable:true}}
]
viewrecords: true
});
});