我想在jTable CRUD Jquery中为每一行添加一个带有somelink的按钮的静态列。 我正在使用他们提供的代码,例如来自jTable网站的
以下是代码:
<script type="text/javascript">
$(document).ready(function () {
//Prepare jTable
$('#PeopleTableContainer').jtable({
title: 'Table of people',
paging: true,
pageSize: 5,
sorting: true,
defaultSorting: 'Name ASC',
actions: {
listAction: 'PersonActionsPagedSorted.php?action=list',
createAction: 'PersonActionsPagedSorted.php?action=create',
updateAction: 'PersonActionsPagedSorted.php?action=update',
deleteAction: 'PersonActionsPagedSorted.php?action=delete'
},
fields: {
PersonId: {
key: true,
create: false,
edit: false,
list: false
},
Name: {
title: 'Author Name',
width: '40%'
},
Age: {
title: 'Age',
width: '20%'
},
Watch: {
title: 'Watch',
width: '20%',
display: function (data) {
return '';
},
RecordDate: {
title: 'Record date',
width: '30%',
type: 'date',
create: false,
edit: false
}
}
});
//Load person list from server
$('#PeopleTableContainer').jtable('load');
});
</script>
关注显示屏中的Watch字段:我想为每一行生成一个带有每行id的href。 我怎么能拿出每一行的id?
答案 0 :(得分:5)
这很简单。请参见display(http://jtable.org/ApiReference#fopt-display)选项。您可以定义这样一个字段:
TestColumn: {
title: 'Test',
display: function (data) {
var $link = $('<a href="...">a link</a>');
$link.click(function(){ /* do something on click */ });
return $link;
}
}
答案 1 :(得分:2)
Link: {
title: 'More Info',
display: function (data) {
return '<a href="@Url.Action("Index", "Demo")">More Info</a>';
}
}