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",
开发者_如何学JAVA 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 id
s 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
andautoheight: true
you probably wanted to useheight:'auto'
. - it is better to use
pager:'#page1'
andpager:'#page2'
instead ofpager: '#page1'
andpager: '#page2'
. - The first grid don't has the column with the name
'Id'
. So you should replacesortname: 'Id'
jqGrid option to for examplesortname: '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
});
});
精彩评论