/** * 将KTable实例解析成HTML * @param KTable $table * @param QueryRequest $request * @return string */ public static function render(KTable $table, QueryRequest $request) { $thead = ''; foreach ($table->getTheads() as $th) { $thead .= $th->render($request); } $tbody = ''; foreach ($table->getTbody() as $tr) { $tbody .= "<tr {$tr->attributes}>"; foreach ($tr->children as $td) { $tbody .= "<td {$td->attributes}>{$td->html}</td>\n"; } $tbody .= '</tr>'; } $attributes = $table->getAttributes(); $tail = $table->getTail(); $html = <<<TABLE <table {$attributes}> <thead> {$thead} </thead> <tbody> {$tbody} </tbody> </table> {$tail} TABLE; return static::wrapper($html); }
public function listTable() { $table = new KTable(); $thead = new TableHead('name'); $thead->setSearchable(); $thead->setSortable(); $thead->setHtml('角色名'); $table->addThead($thead); $thead = new TableHead('display_name'); $thead->setSearchable(); $thead->setHtml('角色描述'); $table->addThead($thead); $thead = new TableHead('action'); $thead->setHtml('操作'); $thead->setFunc(function (Role $role) { return ButtonUtils::block_btn_edit($this, $role); }); $table->addThead($thead); return $table; }