【问题标题】:Adding my own buttons to a Bootgrid table using PHP使用 PHP 将我自己的按钮添加到 Bootgrid 表
【发布时间】:2016-08-05 00:33:36
【问题描述】:

我正在使用 JQuery Bootgrid 进行表格显示、分页、搜索等。我不喜欢命令按钮,我只想在表格中添加简单的 html 按钮,例如:

echo "<td><a href='expensereport.php?source=editexpenses&p_id=$expenseID'><button class='btn btn-primary btn-icon' type='button'><span class='zmdi zmdi-edit'></span></button></a>";

在我使用之前,这种方法效果很好

<table id="data-table"> 

在 bootgrid 上运行。 Bootgrid 在我的表格中根本不会显示该按钮。有谁知道如何关闭 bootgrid 命令按钮,以便我可以添加自己的?我的按钮很好用,直到我添加了 bootgrid,它拒绝在我的表格中显示它们。感谢您的帮助我是 Bootgrid 的新手。

【问题讨论】:

    标签: php jquery jquery-bootgrid


    【解决方案1】:

    看看使用Formatters

    创建一个列,每个单元格都包含您的$expenseID

    确保在费用 ID 列标题上设置了 data-column-id。在本例中,我们将其设置为 data-column-id="expenseId"。您也可以通过将data-visible-in-selection='false'data-visible='false' 添加到列标题来完全隐藏此列。

    在“操作”的列标题中,您还需要通过传递data-formatter 来指定要使用的格式化程序。在这种情况下,我将格式化函数命名为expenseReportEdit,因此我们将使用data-formatter="expenseReportEdit"

    表头的 HTML 标记将是这样的......

    <thead>
        <tr>
            <th data-column-id="expenseId" data-identifier='true' data-visible-in-selection='false' data-visible='false'>Expense ID</th>
            <th data-column-id="expenseActions" data-formatter="expenseReportEdit">Actions</th>
        </tr>
    </thead>
    

    然后像这样创建你的格式化函数..

    $("#yourTableId").bootgrid({
        formatters: {                    
            expenseReportEdit: function (column, row) {
                return "<a href=\"expensereport.php?source=editexpenses&p_id=" + row.expenseId + "\"><button class='btn btn-primary btn-icon' type='button'><span class='zmdi zmdi-edit'></span></button></a>";
            }
        }
    });
    

    【讨论】:

    • 如果我有多个按钮,一个用于删除,一个用于添加,一个用于编辑?
    猜你喜欢
    • 1970-01-01
    • 2015-08-05
    • 2013-03-29
    • 2015-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-15
    • 1970-01-01
    相关资源
    最近更新 更多