gpt4 book ai didi

jquery-plugins - 当 JSON 为数据源时,在 jquery 数据表列中显示图像

转载 作者:行者123 更新时间:2023-12-04 23:25:56 25 4
gpt4 key购买 nike

我正在使用 JQuery 数据表插件来显示类(class)中的学生列表。插件的数据源设置为服务器端操作,它将返回一个包含这些属性(名字、姓氏、年龄、性别....)的 json 对象。我们的要求最近更改为显示基于学生性别的图像(男性/女性)。

我可以加载所有数据,以我想要的方式格式化表格,然后将其转换为 DataTable,但这是不可能的,因为我们有很多记录并且我们正在使用分页。

数据表插件中是否有任何可以进行后期渲染的功能?

最佳答案

使用 mRender option

数据表文档中的代码

$(document).ready(function() {
$('#example').dataTable( {
"aoColumnDefs": [
{
// `data` refers to the data for the cell (defined by `mData`, which
// defaults to the column being worked with, in this case is the first
// Using `row[0]` is equivalent.
"mRender": function ( data, type, row ) {
return data +' '+ row[3];
},
"aTargets": [ 0 ]
},
{ "bVisible": false, "aTargets": [ 3 ] },
{ "sClass": "center", "aTargets": [ 4 ] }
]
} );
} );

链接到工作示例 here

编辑:实现此目的的另一种方法是使用 Daniel 指出的“fnRowCallback”。用这个 link :)

干杯!!

关于jquery-plugins - 当 JSON 为数据源时,在 jquery 数据表列中显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12890049/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com