我正在使用jtable(jtable.org)并创建了一个我想要的表。我无法弄清楚怎么做是围绕行动'createAction'
jtable api中有一个名为:
的对象TotalRecordCount:记录总数(不仅是此页面)。
我想要的是:
if(TotalRecordCount< 5){createAction: 'PersonActionsPagedSorted.php?orderId =& action = create',}
以下是整个代码:
<script type="text/javascript">
jQuery(document).ready(function () {
//Prepare jTable
jQuery('#ext_table').jtable({
//title: 'Create Extensions',
paging: true,
pageSize: 10,
sorting: true,
defaultSorting: 'Extension ASC',
actions: {
listAction: 'PersonActionsPagedSorted.php?orderId=&action=list',
createAction: 'PersonActionsPagedSorted.php?orderId=&action=create',
updateAction: 'PersonActionsPagedSorted.php?action=update',
deleteAction: 'PersonActionsPagedSorted.php?action=delete'
},
fields: {
PersonId: {
key: true,
create: false,
edit: false,
list: false
},
Name: {
title: 'Name',
width: '30%',
sorting:false,
//inputClass: 'validate[required]'
},
emailAddress: {
title: 'Email Address',
width: '20%',
sorting:false
}
});
//Load person list from server
$('#ext_table').jtable('load');
});
</script>
答案 0 :(得分:0)
首先,$ recordCount由SQL查询设置,如:
$sql_select = "SELECT COUNT(*) AS RecordCount FROM myTable";
$stmt = $conn->query($sql_select);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
$recordCount = $result['RecordCount'];
然后将set变量插入到$ jTableResult数组中,其中['TotalRecordCount'] indice类似于:
$jTableResult['TotalRecordCount'] = $recordCount;
我这样说是为了澄清$ recordcount变量已经可用于php而不试图从jtable本身提取它(也就是说,它不是来自jtable的GET或POST数据)。
现在,在您的jtable配置文件中,您可以在其中指定字段和操作,这样您就可以执行以下操作:
actions: {
listAction: 'actions.php?action=list',
<?php if($recordCount <5) { ?>
createAction: 'actions.php?orderId=&action=create',
<?php }else{ ?>
createAction: 'actions.php?action=create',
<?php } ?>
updateAction: 'actions.php?action=update',
deleteAction: 'actions.php?action=delete'
},
我很肯定这是有效的,因为我使用相同的方法来检查$ _SESSION变量,以确定某些操作是否可供用户使用。