In the code sample below, we will add a custom button and when we click on it, an alert message is displayed.
<?php require_once 'jq-config.php'; // include the jqGrid Class require_once "php/jqGrid.php"; // include the driver class require_once "php/jqGridPdo.php"; // Connection to the server $conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD); // Tell the db that we use utf-8 $conn->query("SET NAMES utf8"); // Create the jqGrid instance $grid = new jqGridRender($conn); // Write the SQL Query $grid->SelectCommand = 'SELECT OrderID, OrderDate, CustomerID, ShipName, Freight FROM orders'; // Set output format to json $grid->dataType = 'json'; // Let the grid create the model $grid->setColModel(); // Set the url from where we obtain the data $grid->setUrl('grid.php'); // Set some grid options $grid->setGridOptions(array( "rowNum"=>10, "rowList"=>array(10,20,30), "sortname"=>"OrderID" )); // Enable navigator $grid->navigator = true; // Disable some actions $grid->setNavOptions('navigator', array("excel"=>false,"add"=>false,"edit"=>false,"del"=>false,"view"=>false)); // add a custom button via the build in callGridMethod // note the js: before the function $buttonoptions = array("#pager", array("caption"=>"Custom Button", "onClickButton"=>"js: function(){alert('Custom Button clicked')}") ); $grid->callGridMethod("#grid", "navButtonAdd", $buttonoptions); $grid->renderGrid('#grid','#pager',true, null, null, true,true); $conn = null; ?>