public static function Render($dataModel, $object, $PageSize = 5, $Titulo = '') { include_once 'PhpExt/Ext.php'; include_once 'PhpExt/Data/SimpleStore.php'; include_once 'PhpExt/Data/ArrayReader.php'; include_once 'PhpExt/Data/JsonReader.php'; include_once 'PhpExt/Data/ScriptTagProxy.php'; include_once 'PhpExt/Data/FieldConfigObject.php'; include_once 'PhpExt/Data/StoreLoadOptions.php'; include_once 'PhpExt/Data/HttpProxy.php'; include_once 'PhpExt/Data/JsonStore.php'; include_once 'PhpExt/Button.php'; include_once 'PhpExt/Toolbar/PagingToolbar.php'; include_once 'PhpExt/Grid/ColumnModel.php'; include_once 'PhpExt/Grid/ColumnConfigObject.php'; include_once 'PhpExt/Grid/GridPanel.php'; include_once 'PhpExt/Window.php'; include_once 'PhpExt/Form/FormPanel.php'; include_once 'PhpExt/Ext.php'; include_once 'PhpExt/Data/Store.php'; include_once 'PhpExt/Data/ArrayReader.php'; include_once 'PhpExt/Data/FieldConfigObject.php'; include_once 'PhpExt/Grid/ColumnModel.php'; include_once 'PhpExt/Grid/ColumnConfigObject.php'; include_once 'PhpExt/Panel.php'; include_once 'PhpExt/Grid/GridPanel.php'; include_once 'PhpExt/Grid/RowSelectionModel.php'; include_once 'PhpExt/Listener.php'; include_once 'PhpExt/Config/ConfigObject.php'; include_once 'PhpExt/Form/FormPanel.php'; include_once 'PhpExt/Form/FieldSet.php'; include_once 'PhpExt/Form/TextField.php'; include_once 'PhpExt/QuickTips.php'; include_once 'PhpExt/Layout/ColumnLayout.php'; include_once 'PhpExt/Layout/ColumnLayoutData.php'; include_once 'PhpExt/Layout/FitLayout.php'; $reader = new PhpExt_Data_JsonReader(); $reader->setRoot("topics")->setTotalProperty("totalCount")->setId("ID"); foreach ($object->properties as $k => $v) { $reader->addField(new PhpExt_Data_FieldConfigObject($k)); } $store = new PhpExt_Data_Store(); $store->setUrl('action_main.php')->setReader($reader)->setBaseParams(array("limit" => $PageSize)); $colModel = new PhpExt_Grid_ColumnModel(); foreach ($object->properties as $k => $v) { if (strpos($k, "S_") !== 0) { $colModel->addColumn(PhpExt_Grid_ColumnConfigObject::createColumn($object->properties_desc[$k], $k, $k, null, null, null, true, true)); } } readfile(dirname(__FILE__) . "/local/Tmpl/PhpExt.tmpl"); $selModel = new PhpExt_Grid_RowSelectionModel(); $selModel->setSingleSelect(true)->attachListener("rowselect", new PhpExt_Listener(PhpExt_Javascript::functionDef(null, "Ext.getCmp(\"idGrid\").getForm().loadRecord(rec);", array("sm", "row", "rec")))); // Grid $grid = new PhpExt_Grid_GridPanel("idGrid"); $grid->setStore($store)->setColumnModel($colModel)->setStripeRows(true)->setWidth(500)->setHeight(350)->setTitle("Elementos"); $grid->setSelectionModel($selModel); $paging = new PhpExt_Toolbar_PagingToolbar(); $paging->setStore($store)->setPageSize($PageSize)->setDisplayInfo("Topics {0} - {1} of {2}")->setEmptyMessage("No topics to display"); $grid->setBottomToolbar($paging); $window = new PhpExt_Window(); $window->setTitle($Titulo)->setWidth(600)->setHeight(450)->setMinWidth(300)->setMinHeight(200)->setPlain(true)->setBodyStyle("padding:5px")->setButtonAlign(PhpExt_Ext::HALIGN_CENTER); $window->addButton(PhpExt_Button::createTextButton("Editar")); $window->addButton(PhpExt_Button::createTextButton("Borrar")); $window->addItem($grid); // Ext.OnReady ----------------------- echo PhpExt_Ext::onReady(null, null, $store->getJavascript(false, "store"), $store->load(new PhpExt_Data_StoreLoadOptions(array("start" => 0, "limit" => $PageSize))), $grid->getJavascript(false, "grid"), $window->getJavascript(false, "window"), $window->show()); echo "</script>"; }
public function __construct() { parent::__construct(); $this->setExtClassInfo("Ext.grid.CheckboxSelectionModel", null); }
/* Data array could be used directly also as $store->setData($myData) */ $italicRenderer = PhpExt_Javascript::functionDef("italic", "return '<i>' + value + '</i>'", array("value")); $changeRenderer = PhpExt_Javascript::functionDef("change", "if(val > 0){\r\n return '<span style=\"color:green;\">' + val + '</span>';\r\n }else if(val < 0){\r\n return '<span style=\"color:red;\">' + val + '</span>';\r\n }\r\n return val;", array("val")); $pctChangeRenderer = PhpExt_Javascript::functionDef("pctChange", "if(val > 0){\r\n return '<span style=\"color:green;\">' + val + '%</span>';\r\n }else if(val < 0){\r\n return '<span style=\"color:red;\">' + val + '%</span>';\r\n }\r\n return val;", array("val")); // ColumnModel $colModel = new PhpExt_Grid_ColumnModel(); $colModel->addColumn(PhpExt_Grid_ColumnConfigObject::createColumn("Company", "company", "company", 160, null, null, true, false))->addColumn(PhpExt_Grid_ColumnConfigObject::createColumn("Price", "price", null, 75, null, PhpExt_Javascript::variable("Ext.util.Format.usMoney"), null, true))->addColumn(PhpExt_Grid_ColumnConfigObject::createColumn("Change", "change", null, 75, null, PhpExt_Javascript::variable('change'), null, true))->addColumn(PhpExt_Grid_ColumnConfigObject::createColumn("% Change", "pctChange", null, 75, null, PhpExt_Javascript::variable('pctChange'), null, true))->addColumn(PhpExt_Grid_ColumnConfigObject::createColumn("Last Updated", "lastChange", null, 75, null, PhpExt_Javascript::variable("Ext.util.Format.dateRenderer('m/d/Y')"), null, true)); // Form Panel $gridForm = new PhpExt_Form_FormPanel("company-form"); $gridForm->setFrame(true)->setLabelAlign(PhpExt_Form_FormPanel::LABEL_ALIGN_LEFT)->setTitle("Company Data")->setBodyStyle("padding: 5px;")->setWidth(750)->setLayout(new PhpExt_Layout_ColumnLayout()); // Setup Grid $leftPanel = new PhpExt_Panel(); $leftPanel->setLayout(new PhpExt_Layout_FitLayout()); $selModel = new PhpExt_Grid_RowSelectionModel(); $selModel->setSingleSelect(true)->attachListener("rowselect", new PhpExt_Listener(PhpExt_Javascript::functionDef(null, "Ext.getCmp(\"company-form\").getForm().loadRecord(rec);", array("sm", "row", "rec")))); $grid = new PhpExt_Grid_GridPanel(); $grid->setStore($store)->setColumnModel($colModel)->setSelectionModel($selModel)->setAutoExpandColumn("company")->setHeight(350)->setTitle("Company Data")->setBorder(true)->attachListener("render", new PhpExt_Listener(PhpExt_Javascript::functionDef(null, "g.getSelectionModel().selectRow(0);", array("g")), null, 10)); $leftPanel->addItem($grid); $gridForm->addItem($leftPanel, new PhpExt_Layout_ColumnLayoutData(0.6)); // Setup Fields $rightPanel = new PhpExt_Form_FieldSet(); $rightPanel->setLabelWidth(90)->setTitle("Company Details")->setDefaults(new PhpExt_Config_ConfigObject(array("width" => 140)))->setDefaultType("textfield")->setAutoHeight(true)->setBodyStyle(PhpExt_Javascript::inlineStm("Ext.isIE ? 'padding:0 0 5px 15px;' : 'padding:10px 15px;'"))->setBorder(false)->setCssStyle(new PhpExt_Config_ConfigObject(array("margin-left" => "10px", "margin-right" => PhpExt_Javascript::inlineStm('Ext.isIE6 ? (Ext.isStrict ? "-10px" : "-13px") : "0"')))); $rightPanel->addItem(PhpExt_Form_TextField::createTextField("company", "Name")); $rightPanel->addItem(PhpExt_Form_TextField::createTextField("price", "Price")); $rightPanel->addItem(PhpExt_Form_TextField::createTextField("pctChange", "% Change")); $rightPanel->addItem(PhpExt_Form_TextField::createTextField("lastChange", "Last Updated")); $gridForm->addItem($rightPanel, new PhpExt_Layout_ColumnLayoutData(0.4)); $gridForm->setRenderTo(PhpExt_Javascript::variable("Ext.get('centercolumn')")); //****************************** onReady