我试图将数据与两个按钮的编辑和删除一起加载到bootgrid中。但是没有加载数据。到目前为止,我尝试了以下代码。如何使用json get_data.php页面加载数据。可以有人更正该代码吗。我最近3天都在尝试。我无法得到结果
表格
<table id="grid-basic" class="table table-condensed table-hover table-striped">
<thead>
<tr>
<th data-column-id="id" >Project Name</th>
<th data-column-id="sender">Project Description</th>
<th data-column-id="received" data-order="desc">Project Client</th>
<th data-column-id="commands" data-formatter="commands" data-sortable="false">Commands</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
JQuery
<script>
var grid = $("#grid-basic").bootgrid({
ajax: true,
post: function ()
{
return {
id: "b0df282a-0d67-40e5-8558-c9e93b7befed"
};
},
url: "get_data.php",
formatters: {
"commands": function(column, row)
{
return
"<button type=\"button\" class=\"btn btn-xs btn-default command-edit\" data-row-id=\"" + row.id + "\"><span class=\"fa fa-pencil\"></span></button> " +
"<button type=\"button\" class=\"btn btn-xs btn-default command-delete\" data-row-id=\"" + row.id + "\"><span class=\"fa fa-trash-o\"></span></button>";
}
}
}).on("loaded.rs.jquery.bootgrid", function()
{
/* Executes after data is loaded and rendered */
grid.find(".command-edit").on("click", function(e)
{
alert("You pressed edit on row: " + $(this).data("row-id"));
}).end().find(".command-delete").on("click", function(e)
{
alert("You pressed delete on row: " + $(this).data("row-id"));
});
});
// $("#grid-basic").bootgrid();
</script>
get_data.php
<?php
$conn = mysqli_connect("localhost", "root", "", "crudphp");
$query ="SELECT * FROM records ORDER BY id DESC";
$stmt = $conn->prepare("SELECT * FROM records ORDER BY id DESC ");
$stmt->bind_result($id,$project_name,$project_description,$project_client);
if ($stmt->execute()) {
while ( $stmt->fetch() ) {
$output[] = array ("id"=>$id,"project_name"=>$project_name,"project_description"=>$project_description,"project_client"=>$project_client);
$output = $output[] = $output["current"] = 1; $output['rowCount'] = 10;
}
echo json_encode( $output );
}
$stmt->close();