【发布时间】:2018-09-19 12:28:03
【问题描述】:
我在 Laravel 中使用 jQuery DataTables,我想使用插件的导出功能。
现在我的问题是,在我的表格中,我有一些 HTML,因此我呈现的是一个复选框,而不是实际的文本。
例子
<td>
<span class="{{($r->submitted == 1)?'checkbox-checked':''}}">
<i class="material-icons md-18">check_box</i>
</span>
</td>
当我在 Excel 中导出此表时,我得到了 td 'check_box' 的值,因此 excel 看起来像这样
+-----------+----------+-----------+-----------+--+
| Firstname | Lastname | Option 1 | Option 2 | |
+-----------+----------+-----------+-----------+--+
| Christos | Savva | check_box | check_box | |
+-----------+----------+-----------+-----------+--+
| Second | Person | check_box | check_box | |
+-----------+----------+-----------+-----------+--+
| Third | Person | check_box | check_box | |
+-----------+----------+-----------+-----------+--+
显然这在 excel 文件中没有意义,而在屏幕上很好,因为我渲染了图标。
根据文档,我尝试使用Format output data - export options
var buttonCommon = {
exportOptions: {
format: {
body: function ( data, row, column, node ) {
//Do stuff to replace check_box with word Yes
//or no
return data
}
}
}
};
问题来了。当我从函数返回数据时,它会返回 td 内的整个 html 块。
所以excel看起来像这样
+-----------+----------+---------------------------------------------------------------+---------------------------------------------------------------+--+
| Firstname | Lastname | Option 1 | Option 2 | |
+-----------+----------+---------------------------------------------------------------+---------------------------------------------------------------+--+
| Christos | Savva | <span class="{{($r->submitted == 1)?'checkbox-checked':''}}"> | <span class="{{($r->submitted == 1)?'checkbox-checked':''}}"> | |
| | | | | |
| | | <i class="material-icons md-18">yes</i> | <i class="material-icons md-18">yes</i> | |
| | | | | |
| | | </span> | </span> | |
+-----------+----------+---------------------------------------------------------------+---------------------------------------------------------------+--+
| Second | Person | <span class="{{($r->submitted == 1)?'checkbox-checked':''}}"> | <span class="{{($r->submitted == 1)?'checkbox-checked':''}}"> | |
| | | <i class="material-icons md-18">yes</i> | | |
| | | </span> | <i class="material-icons md-18">yes</i> | |
| | | | | |
| | | | </span> | |
+-----------+----------+---------------------------------------------------------------+---------------------------------------------------------------+--+
| Third | Person | <span class="{{($r->submitted == 1)?'checkbox-checked':''}}"> | <span class="{{($r->submitted == 1)?'checkbox-checked':''}}"> | |
| | | | | |
| | | <i class="material-icons md-18">yes</i> | <i class="material-icons md-18">yes</i> | |
| | | | | |
| | | </span> | </span> | |
+-----------+----------+---------------------------------------------------------------+---------------------------------------------------------------+--+
有谁知道我如何做到这一点?
【问题讨论】:
-
您只显示“已检查”的 sn-ps。未选中伪复选框时 HTML 的外观如何?
-
选中复选框时,我只是用 css 更改颜色,我将其设为绿色,如果未选中,颜色为灰色 @tschitsch 我会检查它,谢谢
标签: jquery datatables export-to-excel