如何在列(DataTables)中实现换行 [英] How can I implement new line in a column (DataTables)

查看:211
本文介绍了如何在列(DataTables)中实现换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SQL查询,它可以获取一些数据( dbtable 表中的 language 列).该查询使用GROUP_CONCAT,因此一个单元格有多个结果,例如

I have an SQL query that grabs some data (language column in dbtable table). The query uses GROUP_CONCAT, so one cell has several results, e.g.

"Ajax, jQuery, HTML, CSS".

我要做的是用新行显示结果,例如:

What I want to do is to show the result in new lines, like:

"Ajax
jQuery
HTML
CSS"

我该怎么做?

我试图通过更改"columns":[{"data":"id"},{"data":"languages"} 来做到这一点……但是它没有用

I tried to make it by changing "columns": [{ "data": "id" }, { "data": "languages" }... but it didn't work.

我还尝试通过在查询中添加< br>"作为分隔符来解决该问题,但是没有用.

I also tried to fix it by adding "< br >" in query as a Separator, but didn't work.

谢谢!

推荐答案

您可以使用 columns.render 这样的列函数:

You can use columns.render function for the column like this:

var table = $('#example').DataTable({
    columns: [
        null,
        null,
        {
            "render": function(data, type, row){
                return data.split(", ").join("<br/>");
            }
        }
    ]
});

工作示例.

希望能有所帮助,并且我已经了解您的问题.

Hope that helps and that I've understood your problem.

这篇关于如何在列(DataTables)中实现换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆