PDA

View Full Version : gird-column render problem?



wanclark
9 Aug 2009, 9:08 AM
I met a problem,


var type_ds = .... (loaded already)

function id2typename(id) {
return type_ds.getById(id).data.typename;
}

var company_cm = new Ext.grid.ColumnModel([
{header:"No.", dataIndex:"id"},
{header:"Company", dataIndex:"comname"},
{header:"Created", dataIndex:"created", renderer:Ext.util.Format.dateRenderer("d/m/Y")},
{header:"Updated", dataIndex:"updated", renderer:Ext.util.Format.dateRenderer("d/m/Y")},
{header:"Type", dataIndex:"typeid", renderer:id2typename},
{header:"Comments", dataIndex:"comments"}
]);
...


when company-grid render, firebug told me type_ds is undefined. how to do it?

mjlecomte
9 Aug 2009, 6:11 PM
You probably have a scope issue. Post a working showcase that simulates your problem for more suggestions.

steffenk
9 Aug 2009, 11:59 PM
if it's in the record you have it in params


function id2typename(value, p, record) {
return record.data.typename;
}

wanclark
10 Aug 2009, 6:38 AM
record only has id, no typename. I thought since type_ds has been defined already, how type_ds is not defined comes?

I use ext3.0 API Documents' doc.js.

The tabPanel. autoLoad:{url:"PurchaseOrder.php", scope:this, scripts:true}

PurchaseOrder.php code as following:


<link rel="stylesheet" type="text/css" href="themes/purchase.css" media="screen" />

<script type="text/javascript">
var status_ds = {}
status_ds.load();

var com_ds = {}
com_ds.load();

var mat_ds = {}
mat_ds.load();

function showPODetails(sm, row, rec) {
if(rec.data.poid) {
podetails_ds.load({params:{start:0, limit:30, poid:rec.data.poid}});
}
}

function id2statusname(id) {
return status_ds.getById(id).data.statusname;
}

function id2comname(id) {
return com_ds.getById(id).data.comname;
}

function id2matname(id) {
return mat_ds.getById(id).data.matname;
}

var po_ds = new Ext.data.Store({
proxy:new Ext.data.HttpProxy({url:"GetPO.php"}),
reader:new Ext.data.JsonReader({
root: "results", total: "total", id: "poid"
}, [
{name: "poid", mapping: "poid"},
{name: "comid", mapping: "comid"},
{name: "created", mapping: "created", type:"date", dateFormat:"U"},
{name: "updated", mapping: "updated", type:"date", dateFormat:"U"},
{name: "delivery", mapping: "delivery"},
{name: "receiver", mapping: "receiver"},
{name: "statusid", mapping: "statusid"},
{name: "amount", mapping:"amount", type:"float"},
{name: "issuedby", mapping:"issuedby"},
{name: "comments", mapping: "comments"}
]),
sortInfo:{field:"poid", direction:"DESC"}
});

var podetails_ds = new Ext.data.Store({
proxy:new Ext.data.HttpProxy({url:"GetPODetails.php"}),
reader:new Ext.data.JsonReader({
root: "results", total: "total", id: "itemid"
}, [
{name: "itemid", mapping: "itemid"},
{name: "poid", mapping: "poid"},
{name: "matid", mapping: "matid"},
{name: "unit", mapping: "unit"},
{name: "qty", mapping: "qty", type:"float"},
{name: "rate", mapping: "rate", type:"float"},
{name: "amount", mapping: "amount", type:"float"},
{name: "reference", mapping: "reference"},
{name: "receivedQty", mapping: "receivedQty", type:"float"},
{name: "invoicedQty", mapping: "invoicedQty", type:"float"},
{name: "comments", mapping: "comments"}
]),
sortInfo:{field:"itemid", direction:"ASC"}
});

var po_cm = new Ext.grid.ColumnModel([
{header:"No.", dataIndex:"poid"},
{header:"Supplier", dataIndex:"comid", renderer:id2supname},
{header:"Created", dataIndex:"created", renderer:Ext.util.Format.dateRenderer("d/m/Y")},
{header:"Updated", dataIndex:"updated", renderer:Ext.util.Format.dateRenderer("d/m/Y")},
{header:"Deliver to", dataIndex:"delivery"},
{header:"Receiver", dataIndex:"receiver"},
{header:"Status", dataIndex:"statusid", renderer:id2statusname},
{header:"Amount", dataIndex:"amount", renderer:Ext.util.Format.usMoney},
{header:"Issued by", dataIndex:"issuedby"},
{header:"Comments", dataIndex:"comments"}
]);

var podetails_cm = new Ext.grid.ColumnModel([
new Ext.grid.CheckboxSelectionModel(),
new Ext.grid.RowNumberer(),
{header:"S/N", dataIndex:"itemid", hidden:true},
{header:"PO No.", dataIndex:"poid", hidden:true},
{header:"Mat ID", dataIndex:"matid", renderer:id2matname},
{header:"Unit", dataIndex:"unit"},
{header:"Qty", dataIndex:"qty"},
{header:"Rate", dataIndex:"rate", renderer:Ext.util.Format.usMoney},
{header:"Amount", dataIndex:"amount", renderer:Ext.util.Format.usMoney},
{header:"Reference", dataIndex:"reference"},
{header:"R-Qty", dataIndex:"receivedQty"},
{header:"I-Qty", dataIndex:"InvoicedQty"},
{header:"Comments", dataIndex:"comments"}
]);

var po_grid = new Ext.grid.GridPanel({
id:"po-grid",
region:"center",
border:false,
store:po_ds,
cm:po_cm,
// plugins:po_gridfilter,
loadMask: true,
viewConfig: { forceFit: true },
sm:new Ext.grid.RowSelectionModel({
singleSelect:true,
listeners:{ rowselect: showPODetails }
}),
autoHeight:true,
tbar:[<?php echo $js_tbar;?>],
bbar:new Ext.PagingToolbar({
pageSize: 30,
store: po_ds,
displayInfo: true,
displayMsg: "Displaying {0} - {1} of {2}",
emptyMsg: "No Data to display"
})
});

var podetails_grid = new Ext.grid.GridPanel({
id:"podetails-grid",
region:"south",
border:false,
store:podetails_ds,
cm:podetails_cm,
loadMask:true,
collapsible:true,
split:true,
collapseMode:"mini",
height:200,
//tbar:[],
bbar:new Ext.PagingToolbar({
pageSize: 10,
store: podetails_ds,
displayInfo: true,
displayMsg: 'Displaying Suppliers {0} - {1} of {2}',
emptyMsg: "No Data to display"
})
});

po_ds.load({params:{start:0, limit:30}});
podetails_ds.load({params:{start:0, limit:30}});

var po_layout = new Ext.Panel({
renderTo:Ext.getCmp("tabs-po").body,
height:Ext.getCmp("tabs-po").getInnerHeight(),
layout: 'border',
items:[po_grid, podetails_grid]
});

</script>

mjlecomte
15 Aug 2009, 9:46 AM
Your first post says something about a firebug error about type_ds. When I look at your post above I don't find any type_ds.