Simple Shopping Cart Using the Action Column

phpgrid shopping cart

In the action column, it is possible to add additional links or buttons beside the CRUD buttons with phpGrid custom JSON property “cust_prop_jsonstr” For example, you can use “cust_prop_jsonstr to insert “add to cart” button via the property called actionsNavOptions.

In the example below, the onClick event call back function simply returns an alert message with the rowid. That is only the tip of the iceberg. By using Ajax, the options.rowid could return the unique key of the row to a server-side script for much more complex workflow such as add to cart, add new users etc.

$dg = new C_DataGrid("SELECT * FROM orders", "orderNumber", "orders");
$dg->cust_prop_jsonstr = 'actionsNavOptions: {
                addUsericon: "fa-user-plus",
                addUsertitle: "Add user",
                deleteUsericon: "fa-user-times",
                deleteUsertitle: "Delete user",
                addToCarticon: "fa-cart-plus",
                addToCarttitle: "Add item to the cart",
                custom: [
                    { action: "addUser", position: "first", onClick: function (options) { alert("Add user, rowid=" + options.rowid); } },
                    { action: "addToCart", position: "first", onClick: function (options) { alert("Add to Cart, rowid=" + options.rowid); } },
                    { action: "deleteUser", onClick: function (options) { alert("Delete user, rowid=" + options.rowid); } }
                ]
            },';
$dg->add_column("actions", array('name'=>'actions', 
	'sortable'=>false,
    'index'=>'actions',
    'width'=>'150',
    'formatter'=>'actions',
    'formatoptions'=>array('keys'=>true, 'editbutton'=>true, 'delbutton'=>true)),'Actions');
$dg->enable_edit();
$dg -> display();

Online Demo (Scroll all the way to the right to view the Action column)