Skip to content

Commit 4da4fad

Browse files
committed
Fix wenzhixin#546, wenzhixin#500, wenzhixin#119: Keep all data-* attributes when transform from normal table.
1 parent 74cb633 commit 4da4fad

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/bootstrap-table.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@
357357
// save td's id and class
358358
row['_' + field + '_id'] = $(this).attr('id');
359359
row['_' + field + '_class'] = $(this).attr('class');
360-
row['_' + field + '_data_value'] = $(this).attr('data-value');
360+
row['_' + field + '_data'] = $(this).data();
361361
});
362362
data.push(row);
363363
});
@@ -497,8 +497,8 @@
497497

498498
if (index !== -1) {
499499
this.data.sort(function (a, b) {
500-
var aa = a['_' + name + '_data_value'] || a[name],
501-
bb = b['_' + name + '_data_value'] || b[name],
500+
var aa = a[name],
501+
bb = b[name],
502502
value = calculateObjectValue(that.header, that.header.sorters[index], [aa, bb]);
503503

504504
if (value !== undefined) {
@@ -1030,6 +1030,7 @@
10301030
cellStyle = {},
10311031
id_ = '',
10321032
class_ = that.header.classes[j],
1033+
data_ = '',
10331034
column = that.options.columns[getFieldIndex(that.options.columns, field)];
10341035

10351036
style = sprintf('style="%s"', csses.concat(that.header.styles[j]).join('; '));
@@ -1044,9 +1045,6 @@
10441045
if (item['_' + field + '_class']) {
10451046
class_ = sprintf(' class="%s"', item['_' + field + '_class']);
10461047
}
1047-
if (item['_' + field + '_data_value']) {
1048-
class_ = sprintf(' data-value="%s"', item['_' + field + '_data_value']);
1049-
}
10501048
cellStyle = calculateObjectValue(that.header,
10511049
that.header.cellStyles[j], [value, item, i], cellStyle);
10521050
if (cellStyle.classes) {
@@ -1060,6 +1058,16 @@
10601058
style = sprintf('style="%s"', csses_.concat(that.header.styles[j]).join('; '));
10611059
}
10621060

1061+
if (item['_' + field + '_data'] && !$.isEmptyObject(item['_' + field + '_data'])) {
1062+
$.each(item['_' + field + '_data'], function (k, v) {
1063+
// ignore data-index
1064+
if (k === 'index') {
1065+
return;
1066+
}
1067+
data_ += sprintf(' data-%s="%s"', k, v);
1068+
});
1069+
}
1070+
10631071
if (column.checkbox || column.radio) {
10641072
type = column.checkbox ? 'checkbox' : type;
10651073
type = column.radio ? 'radio' : type;
@@ -1087,7 +1095,7 @@
10871095
getPropertyFromOther(that.options.columns, 'field', 'title', field)) : '',
10881096
sprintf('<span class="value">%s</span>', value),
10891097
'</div>'].join('') :
1090-
[sprintf('<td%s %s %s>', id_, class_, style),
1098+
[sprintf('<td%s %s %s %s>', id_, class_, style, data_),
10911099
value,
10921100
'</td>'].join('');
10931101

0 commit comments

Comments
 (0)