Tablesorter 2.28.7 - 使用 select-filter 时无法读取未定义的 属性 'text'
Tablesorter 2.28.7 - Cannot read property 'text' of undefined when using select-filter
我正在使用 tablesorter v. 2.28.7 的分支,我正在尝试添加 select 过滤器。在使用 select 过滤器之前一切都按预期工作,因此使用普通文本过滤...
这是我前面的table
<table id="stopsTable">
<thead>
<tr>
<th><spring:message code="id" /></th>
<th><spring:message code="stop.user" /></th>
<th data-placeholder="---"><spring:message code="stop.park" /></th>
<th><spring:message code="stop.from" /></th>
<th><spring:message code="stop.to" /></th>
<th><spring:message code="stop.price" /></th>
<th><spring:message code="stop.status" /></th>
<th class="filter-false"><span class="pull-right"><spring:message
code="actions" /></span></th>
</tr>
</thead>
然后是 js
$(document).ready(function() {
$("#stopsTable")
.tablesorter({
headers: {
7: {sorter: false},
3: {sorter: 'customDate'},
4: {sorter: 'customDate'}
},
theme: "bootstrap",
widthFixed: true,
headerTemplate : '{content} {icon}', // new in v2.7. Needed to add the bootstrap icon!
widgets : [ "uitheme", "filter", "columns", "zebra", "pager" ],
widgetOptions : {
zebra : ["even", "odd"],
columns: [ "primary", "secondary", "tertiary" ],
filter_reset : ".reset",
filter_cssFilter: "form-control",
pager_output: '{startRow:input} {endRow} / {totalRows} row',
pager_updateArrows: true,
pager_startPage: 0,
pager_size: 10,
pager_removeRows: false,
filter_ignoreCase : true,
filter_searchDelay : 300,
filter_functions : {
2 : true,
},
},
})
});
$.tablesorter.addParser({
id: "customDate",
is: function(s) {
//return false;
//use the above line if you don't want table sorter to auto detected this parser
//21/04/2010 03:54 is the used date/time format
return /\d{1,2}\/\d{1,2}\/\d{1,4} \d{1,2}:\d{1,2}/.test(s);
},
format: function(s) {
s = s.replace(/\-/g," ");
s = s.replace(/:/g," ");
s = s.replace(/\./g," ");
s = s.replace(/\//g," ");
s = s.split(" ");
return $.tablesorter.formatFloat(new Date(s[2], s[1]-1, s[0], s[3], s[4]).getTime());
},
type: "numeric"} );
我也尝试将 "filter-select" class 添加到,但出现此异常
Uncaught TypeError: Cannot read property 'text' of undefined
此时:
jquery.tablesorter.widgets.js:2003
在共享的演示中,HTML 无效...在 </thead>
和 <tbody>
之间是一个额外的 <tr>
</thead>
<tr>
<tbody>
这导致了 javascript 错误。如果您删除 <tr>
,该演示可以正常运行 - https://jsfiddle.net/bbxxomhx/401/
我正在使用 tablesorter v. 2.28.7 的分支,我正在尝试添加 select 过滤器。在使用 select 过滤器之前一切都按预期工作,因此使用普通文本过滤...
这是我前面的table
<table id="stopsTable">
<thead>
<tr>
<th><spring:message code="id" /></th>
<th><spring:message code="stop.user" /></th>
<th data-placeholder="---"><spring:message code="stop.park" /></th>
<th><spring:message code="stop.from" /></th>
<th><spring:message code="stop.to" /></th>
<th><spring:message code="stop.price" /></th>
<th><spring:message code="stop.status" /></th>
<th class="filter-false"><span class="pull-right"><spring:message
code="actions" /></span></th>
</tr>
</thead>
然后是 js
$(document).ready(function() {
$("#stopsTable")
.tablesorter({
headers: {
7: {sorter: false},
3: {sorter: 'customDate'},
4: {sorter: 'customDate'}
},
theme: "bootstrap",
widthFixed: true,
headerTemplate : '{content} {icon}', // new in v2.7. Needed to add the bootstrap icon!
widgets : [ "uitheme", "filter", "columns", "zebra", "pager" ],
widgetOptions : {
zebra : ["even", "odd"],
columns: [ "primary", "secondary", "tertiary" ],
filter_reset : ".reset",
filter_cssFilter: "form-control",
pager_output: '{startRow:input} {endRow} / {totalRows} row',
pager_updateArrows: true,
pager_startPage: 0,
pager_size: 10,
pager_removeRows: false,
filter_ignoreCase : true,
filter_searchDelay : 300,
filter_functions : {
2 : true,
},
},
})
});
$.tablesorter.addParser({
id: "customDate",
is: function(s) {
//return false;
//use the above line if you don't want table sorter to auto detected this parser
//21/04/2010 03:54 is the used date/time format
return /\d{1,2}\/\d{1,2}\/\d{1,4} \d{1,2}:\d{1,2}/.test(s);
},
format: function(s) {
s = s.replace(/\-/g," ");
s = s.replace(/:/g," ");
s = s.replace(/\./g," ");
s = s.replace(/\//g," ");
s = s.split(" ");
return $.tablesorter.formatFloat(new Date(s[2], s[1]-1, s[0], s[3], s[4]).getTime());
},
type: "numeric"} );
我也尝试将 "filter-select" class 添加到,但出现此异常
Uncaught TypeError: Cannot read property 'text' of undefined
此时:
jquery.tablesorter.widgets.js:2003
在共享的演示中,HTML 无效...在 </thead>
和 <tbody>
之间是一个额外的 <tr>
</thead>
<tr>
<tbody>
这导致了 javascript 错误。如果您删除 <tr>
,该演示可以正常运行 - https://jsfiddle.net/bbxxomhx/401/