【发布时间】:2012-05-12 15:17:40
【问题描述】:
在我的 Web 应用程序中,我为用户记录维护了表。记录在客户端发送时添加和删除,然后用户单击保存按钮以保存在服务器上完成的所有操作。
我已将表格排序器应用于表格上的排序功能。但令人惊讶的是,排序功能仅适用于 ID 字段,即表的第一个字段,但对于所有其他字段,它会给出错误(来自 chrome 的错误跟踪)
Uncaught TypeError: Cannot read property 'type' of undefined
multisortjquery.tablesorter.js:600
$.extend.tablesorter.construct.each.$headers.click.mousedown.onselectstart
这是表结构。
<table id="contentTable" class="tablesorter">
<thead>
<tr>
<th> ID </th>
<th> Name </th>
<th> Birth Date </th>
<th> City </th>
<th id="actionheader"> Action</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
在此我动态添加数据。 在这种情况下,排序仅适用于第一个字段,即 ID 字段
这就是我初始化 tableSorting 的方式。
function initializeTableSorting() {
$("#contentTable").tablesorter({
sortList : [[0, 0]],
headers : {
0 : {
sorter : "integer"
},
1 : {
sorter : "text"
},
2 : {
sorter : false
},
3 : {
sorter : "text"
},
4 : {
sorter : false
}
}
});
}
如果我从初始化中删除 false 选项,我怎样才能使所有字段都工作,甚至 日期字段也可以工作?
【问题讨论】:
标签: jquery jquery-plugins tablesorter