盾力力/数据表

服务器端数据表包

v1.0.0 2022-07-21 17:54 UTC

This package is auto-updated.

Last update: 2024-09-25 04:10:34 UTC


README

盾力力数据表 Shieldforce

非常重要的一点是,本版本仅使用boostrap 5,因此,如果未使用bootstrap,可能会影响某些样式。

非常重要的一点是,本版本仅使用jquery-3.5.1,因此,如果您的jquery版本不同,可能会影响可用性。

好处是,由于标签是独立的,您可以在代码的特定位置调用,而不会影响整个项目!

要求

  • PHP >= 8.1
  • Composer >= 2
  • 自动加载开启

安装包

composer require shieldfroce/datatable:1.0.0

简单实现示例(前端)!

img.png

负责渲染css调用

<?php echo \Shieldforce\Frontend\CssRender\Ghost::head() ?>

负责创建列

<?php 
    echo \Shieldforce\Backend\DatatableRender::renderHtmlTable([
        [ "name" => "id",     "data" => "id",     "title" => "#",     "class" => 'text-danger', 'width' => '10%', "orderable" => true, ],
        [ "name" => "name",   "data" => "name",   "title" => "Nome",  "class" => 'text-dark',   'width' => '50%', "orderable" => true  ],
        [ "name" => "age",    "data" => "age",    "title" => "Idade", "class" => 'text-dark',   'width' => '20%', "orderable" => true  ],
        [ "name" => "action", "data" => "action", "title" => "Ação",  "class" => 'text-dark',   'width' => '20%', "orderable" => true  ],
    ]);
?>

负责渲染javascript调用

<?php echo \Shieldforce\Frontend\JsRender\Ghost::js() ?>

负责渲染javascript逻辑

<?php echo \Shieldforce\Frontend\JsRender\GhostExecution::js("server.php") ?>

简单实现示例(后端)!

img_1.png

// 模拟数据的数组示例

$list = [];
for ($i=1;$i<=50000;$i++) {
    $age = rand(10, 80);
    $list[$i] = ["id"=>"{$i}", "name"=>"Firstname Lastname {$i}", "age"=>"{$age}"];
}

// 构建并渲染数据表的结果

echo \Shieldforce\Backend\DatatableReturn::baseReturn($_POST, $list, function ($nestedData, $col, $r){

    // Configura as colunas de retorno com opção de criar lógica customizada!
    
    if($col=="id") {
        $nestedData["$col"] = $r["id"] ?? "-";
    } elseif($col=="name") {
        $nestedData["$col"] = $r["name"] ?? "-";
    } elseif($col=="age") {
        $nestedData["$col"] = $r["age"] ?? "-";
    } elseif($col=="action") {
        $nestedData["$col"]   = "-";
    } else {
        $nestedData["$col"] = "-";
    }

    // Retorna as colunas de resultado
    
    return $nestedData;
});