【发布时间】:2013-05-25 08:16:39
【问题描述】:
我们可以在 jtable 中添加自定义按钮吗?是否有任何选项可用于创建按钮?
意思是如果我想要一个按钮来创建PDF,那我该怎么办?
【问题讨论】:
标签: jquery jquery-jtable
我们可以在 jtable 中添加自定义按钮吗?是否有任何选项可用于创建按钮?
意思是如果我想要一个按钮来创建PDF,那我该怎么办?
【问题讨论】:
标签: jquery jquery-jtable
要插入一个按钮,您必须使用display: 函数,并根据您的选择自定义它;即我创建了一个带有按钮的列:变量data 包含当前记录的数据。
$(document).ready(function () {
$('#StudentTableContainer').jtable({
title: 'The Student List',
paging: true, //Enable paging
pageSize: 10, //Set page size (default: 10)
sorting: true, //Enable sorting
defaultSorting: 'Name ASC', //Set default sorting
actions: {
listAction: '/Demo/StudentList',
deleteAction: '/Demo/DeleteStudent',
updateAction: '/Demo/UpdateStudent',
createAction: '/Demo/CreateStudent'
},
fields: {
StudentId: {
key: true,
create: false,
edit: false,
list: false
},
Name: {
title: 'Name',
width: '40%'
},
EmailAddress: {
title: 'Email address',
list: false
},
Password: {
title: 'User Password',
type: 'password',
list: false
},
Gender: {
title: 'Gender',
width: '20%',
options: { 'M': 'Male', 'F': 'Female' }
},
MyButton: {
title: 'MyButton',
width: '40%',
display: function(data) {
return '<button type="button" onclick="alert(' + data.record.StudentId + ')">create PDF</button> ';
}
},
}
});
//Load student list from server
$('#StudentTableContainer').jtable('load');
});
【讨论】:
$row = array("name"=>"me"); $jTableResult = array(); $jTableResult['TotalRecordCount'] = $num_rows; $jTableResult['Result'] = "OK"; $jTableResult['Records'] = $rows; print json_encode($jTableResult); 所以定义了 data.record.name。另请查看文档以获取更多帮助:jtable.org/ApiReference#fopt-display关于附加事件,试试这个,它应该可以工作:$( ".myclassbutton" ).bind( "click", function() { alert( "User clicked on 'foo.'" ); });