Hi, This is my first grid code.
$(function () {
var data = [
[' LUPUS', '364,397','149,578','722,485','216,746','616,499'],
['TARG', '364,397','145,759','726,043','217,813','602,508' ],
['STX ', '402,954','161,178','696,850','209,055','671,647' ],
['TOPAZ', '442,182','176,873','743,550','223,065','734,120' ],
['MBER', '440,991','176.396','744,245','223,273','731217'],
['MAX', '347,076','138,830','673,964','202,189','552,763'],];
var obj = {
editor:false,resizable:false, sortable:false, scrollModel:{autoFit:false, theme:false},draggable:false, collapsible: false,
showTitle: true, showBottom:false,};
obj.colModel = [
{ title: "Ves", align:'left',cls:'gre1',width:130},
{ title: "Std 1 ", align:'center',width:100},
{ title: "Std 2", align:'center',width:100},
{ title: "Std 3 ", align:'center',width:100 },
{ title: "Previous", align:'center', cls:'tp-whired' ,width:100},
{ title: "Total Income", align:'center',width:100},];
obj.dataModel = { data: data };
$("#totalpp_tab_main").pqGrid(obj);
$( "#totalpp_tab_main").pqGrid({
refresh: footer123 //call back function
});
});
In this first grid I used call back function to do some calculation . And following is my second grid.
$(function () {
var data = [
['LUPUS','87000.00','43751.00','40000.00'],
['TARG','37000.00','44192.64','40000.00'],
['STX ','37000.00','41671.25','40000.00'],
['TOPAZ','37000.00','42700.42','40000.00'],
['MBER','37000.00','42706.75','40000.00'],
['MAX','37000.00','43734.50','40000.00'],];
var obj = { width: 1342,height: 450, numberCell:false,editor: {type: 'textbox'},resizable:false, scrollModel:{autoFit:false, theme:false},sortable:false,draggable:false,minWidth: 30,editable: false,collapsible: false, showTitle: true, showBottom:false,};
obj.colModel = [
{ title: "Ves", cls:'ca-vess',align:'left',width:150, halign:"center"},
{ title: "Data",align:'center', width:350,colModel:[{title:"UMS (VOYAGE N.1)",align:'center', cls:'ca-vess1',width:350},{title:"DO (VOYAGE N.2)",align:'center', cls:'ca-vess1',width:350},{title:"GO (VOYAGE N.3)",align:'center', cls:'ca-vess1',width:350}]},
];
obj.dataModel = { data: data };
$("#cargolc_tab_main").pqGrid(obj);
});
My tab event code is
$('#tabs').tabs({
activate:function(event,ui){
if(ui.newTab.index()==0) {
var $grid=$("#totalpp_tab_main");
$grid.pqGrid("option", {height:($( window ).height()+740)/2.9, width: $( window ).width()-23});
$grid.pqGrid("refreshView");
}
if(ui.newTab.index()==1){
var $grid=$("#additionalpp_tab_main");
$grid.pqGrid("option", {height:($( window ).height()+740)/2.9, width: $( window ).width()-23});
$grid.pqGrid("refreshView");
}
$grid.pqGrid( 'refresh' );
}
});
Following is my function to do the calculation. This function present in different js file.
function footer123 ( event, ui ) {
var $grid=$("#totalpp_tab_main");
var CM = $grid.pqGrid("option", "colModel");
var DM = $grid.pqGrid("option", "dataModel");
var data = DM.data;
var $grid1=$("#cargolc_tab_main");
var CM1 = $grid1.pqGrid("option", "colModel");
var DM1 = $grid1.pqGrid("option", "dataModel");
var data1 = DM1.data;
for(k=0; k<data.length;k++){
var cfval=data1[k][0];
var r;
for (var j=0;j<data.length;j++){
var rowData=data[ j ];
for(var dataIndx in rowData ){
if(rowData[dataIndx] == cfval){
r = j;
break;
}
}
}
if(data[r][0]==data1[k][0]){
data[r][1]=((parseInt(data1[k][1]))*2)+((parseInt(data1[k][2]))*3);
}
else{
alert("Wrong Name");
}
$( "#totalpp_tab_main" ).pqGrid( "refreshCell",{ rowIndx:r, dataIndx: 1 });
}
};
In the above function am getting the value of the data1[0][1] and data1[0][2]value in second grid and doing the calculation and printing the value in first grid in the position of data[0][1] and it goes on. For this I need to check the value of data[n][0] in both first grid and second grid. if both are same then only it will print the value.
Now if am dynamically changing the value in the second grid it needs to change the value in the first grid without reload the page.