我是否可以知道是否可以将图片或图像放入DataTables(http://datatables.net/)的行中,以及如何进行操作?
Gre*_*tit 16
[编辑:请注意,以下代码和说明使用以前的DataTables API(1.9及以下版本?); 它很容易转换成当前的API(在大多数情况下,只是抛弃匈牙利表示法(例如"fnRowCallback"只是变成"rowCallback")但我还没有这样做.我认为向后兼容性仍然存在,但你应该在可能的情况下寻找更新的约定]
原始答复如下:
丹尼尔说的是真的,但并不一定说它是如何完成的.而且有很多方法.以下是主要内容:
1)数据源(服务器或其他)提供完整的图像标记作为数据集的一部分.不要忘记转义任何需要转义为有效JSON的字符
2)数据源为一个或多个字段提供所需信息.例如,名为"图像链接"的字段只有该Images/PictureName.png部分.然后在fnRowCallback中使用此数据创建图像标记.
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
var imgLink = aData['imageLink']; // if your JSON is 3D
// var imgLink = aData[4]; // where 4 is the zero-origin column for 2D
var imgTag = '<img src="' + imgLink + '"/>';
$('td:eq(4)', nRow).html(imgTag); // where 4 is the zero-origin visible column in the HTML
return nRow;
}
Run Code Online (Sandbox Code Playgroud)
3)与上面类似,但您只需更新将图像作为背景的类,而不是添加整个标记.您可以对重复元素的图像执行此操作,而不是一次性或唯一的数据.
Aru*_*E S 12
是的,简单的方法(Jquery Datatable)
<script>
$(document).ready(function () {
$('#example').dataTable({
"processing": true, // control the processing indicator.
"serverSide": true, // recommended to use serverSide when data is more than 10000 rows for performance reasons
"info": true, // control table information display field
"stateSave": true, //restore table state on page reload,
"lengthMenu": [[10, 20, 50, -1], [10, 20, 50, "All"]], // use the first inner array as the page length values and the second inner array as the displayed options
"ajax":{
"url": "@string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~"))/Home/AjaxGetJsonData",
"type": "GET"
},
"columns": [
{ "data": "Name", "orderable" : true },
{ "data": "Age", "orderable": false },
{ "data": "DoB", "orderable": true },
{
"render": function (data, type, JsonResultRow, meta) {
return '<img src="Content/'+JsonResultRow.ImageAddress+'">';
}
}
],
"order": [[0, "asc"]]
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
你的意思是表格列内的图像?
是的,只需放置一个html图片标签即可
像这样
<img src="Images/PictureName.png">
Run Code Online (Sandbox Code Playgroud)
而不是将数据(一些字符串)放入一列只是把上面的html标签....