CFGRID Custom Delete
I am using an example I customised from Dan Vega's Blog on CFGRID. I wanted to add my own delete function to the grid and not using the delete="yes". The function needed to pass the selected ID to a CFC delete function. I decided to use my new found love of cfajaxproxy, what I am not sure about is if I have gone about doing this in the best way. I could not find any examples and my solution does work well, but I cannot help feeling I have gone the long way around this? Without knowing where to look I cannot be sure.
Anyway here is what I did, right or wrong it works.
>Created the CFC (with has my delete function) as a JavaScript object.<cfajaxproxy cfc="live.components.orders" jsclassname="callordersCFC"/>
Setup my grid and buttons, just the delete button in this example.
<InvalidTag type="text/javascript">
function init(){
grid = ColdFusion.Grid.getGridObject("ordersSearch");
var gridHead = grid.getView().getHeaderPanel(true);
var tbar = new Ext.Toolbar(gridHead);
//delete order button
tbar.addButton({
text:"Delete Order",
cls:"x-btn-text-icon",
icon:"./images/icons/package_delete.png",
handler:onDeleteOrder
});
console.log(tbar);
}
Next created my delete function, first it gets the selected record from the grid. I use the function in CFC object created in the cfajaxproxy and return the results in the another alert box. Last I refresh the grid to show the updated results. Very simple example.
function onDeleteOrder(button,event){
var record = grid.getSelections();
var orderId = record[0].data.ORDER_ID;
confirmed = window.confirm("This action will permanently delete Order ID: " orderId ". This action can not be reversed are you sure?") ;
if (confirmed)
{
alert((new callordersCFC()).deleteOrderById(orderId=orderId));
ColdFusion.Grid.refresh('ordersSearch', true);
}
else
{
}
console.log(button);
console.log(event);
}



There are no comments for this entry.
[Add Comment] [Subscribe to Comments]