KoolGrid support various type of columns:
- - GridBoundColumn
- - GridDateTimeColumn
- - GridDropDownColumn
- - GridBooleanColumn
- - GridImageColumn
- - GridCustomColumn
- - GridCommandColumn
- - GridEditDeleteColumn
- - GridExpandDetailColumn
- - GridRowSelectColumn
- ...
Beside most-used columns which are provided, you can write your own column type and add to KoolGrid.
<?php
$KoolControlsFolder = "../../../../KoolControls";//Relative path to "KoolPHPSuite/KoolControls" folder
require $KoolControlsFolder."/KoolAjax/koolajax.php";
$koolajax->scriptFolder = $KoolControlsFolder."/KoolAjax";
require $KoolControlsFolder."/KoolGrid/koolgrid.php";
require $KoolControlsFolder."/KoolGrid/ext/datasources/MySQLiDataSource.php";
require $KoolControlsFolder."/KoolCalendar/koolcalendar.php";
$ds = new MySQLiDataSource($db_con);//This $db_con link has been created inside KoolPHPSuite/Resources/runexample.php
$ds->SelectCommand = "select orderNumber,orderDate,status,comments from orders";
$ds->UpdateCommand = "update orders set orderDate='@orderDate', status='@status', comments='@comments' where orderNumber=@orderNumber";
$ds->DeleteCommand = "delete from orders where orderNumber=@orderNumber";
$grid = new KoolGrid("grid");
$grid->scriptFolder = $KoolControlsFolder."/KoolGrid";
$grid->styleFolder="sunset";
$grid->AjaxEnabled = true;
$grid->DataSource = $ds;
$grid->MasterTable->Pager = new GridPrevNextAndNumericPager();
$grid->Width = "655px";
$grid->ColumnWrap = true;
$grid->AllowEditing = true;
$grid->AllowDeleting = true;
$grid->MasterTable->EditSettings->Mode = "form";
$grid->ShowFooter = true;
$column = new GridBoundColumn();
$column->DataField = "orderNumber";
$column->HeaderText = "Order number";
$column->ReadOnly = true;
$column->FooterText = "Total Sum: ";
$column->Aggregate = "Sum";
$grid->MasterTable->AddColumn($column);
$column = new GridDateTimeColumn();
$column->DataField = "orderDate";
$column->HeaderText = "Order date";
$column->FormatString = "M d, Y";
$column->Width = '100px';
//Assign datepicker for GridDateTimeColumn
$column->Picker = new KoolDatePicker();
$column->Picker->scriptFolder = $KoolControlsFolder."/KoolCalendar";
$column->Picker->styleFolder = "sunset";
$column->Picker->DateFormat = "M d, Y";
$grid->MasterTable->AddColumn($column);
$column = new GridDropDownColumn();
$column->DataField = "status";
$column->HeaderText = "Status";
$column->AddItem("In Process");
$column->AddItem("On Hold");
$column->AddItem("Disputed");
$column->AddItem("Cancelled");
$column->AddItem("Resolved");
$column->AddItem("Shipped");
$grid->MasterTable->AddColumn($column);
$column = new GridBoundColumn();
$column->DataField = "comments";
$column->HeaderText = "Comment";
$column->MaxLength = 100;
$grid->MasterTable->AddColumn($column);
$column = new GridEditDeleteColumn();
$column->HeaderText = "GridEditDeleteColumn";
$column->Align = "center";
$grid->MasterTable->AddColumn($column);
$grid->Process();
?>
<b>Field Comment's max length is 100 characters.</b>
<form id="form1" method="post">
<?php echo $koolajax->Render();?>
<?php echo $grid->Render();?>
<div style="margin-top:10px;"><i>* <u>Note</u>:</i>Generate your own grid with <a style="color:#B8305E;" target="_blank" href="http://codegen.koolphp.net/grid/">Code Generator</a></div>
</form>