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.

view plain print about
1<cfajaxproxy cfc="live.components.orders" jsclassname="callordersCFC"/>

Setup my grid and buttons, just the delete button in this example.

view plain print about
1<InvalidTag type="text/javascript">
2function init(){
3 grid = ColdFusion.Grid.getGridObject("ordersSearch");
4 var gridHead = grid.getView().getHeaderPanel(true);
5 var tbar = new Ext.Toolbar(gridHead);
6
7//delete order button
8     tbar.addButton({
9 text:"Delete Order",
10 cls:"x-btn-text-icon",
11 icon:"./images/icons/package_delete.png",
12 handler:onDeleteOrder
13 });
14 console.log(tbar);         
15 }

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.

view plain print about
1function onDeleteOrder(button,event){
2var record = grid.getSelections();
3var orderId = record[0].data.ORDER_ID;
4confirmed = window.confirm("This action will permanently delete Order ID: " orderId ". This action can not be reversed are you sure?") ;
5if (confirmed)
6{
7alert((new callordersCFC()).deleteOrderById(orderId=orderId));
8ColdFusion.Grid.refresh('ordersSearch', true);
9}
10else
11{
12
13}
14 console.log(button);
15 console.log(event);
16
17}

Jan05

Comments 0