【发布时间】:2015-01-19 15:13:32
【问题描述】:
我正在尝试通过使用光滑网格来实现“同一单元格中的文本和图像”。我没有找到任何符合我要求的答案。谁能回答我的问题...?
【问题讨论】:
标签: slickgrid
我正在尝试通过使用光滑网格来实现“同一单元格中的文本和图像”。我没有找到任何符合我要求的答案。谁能回答我的问题...?
【问题讨论】:
标签: slickgrid
单元格自定义通常通过formatters 处理。
注意row height 可以通过grid options 设置,但will be static,因此如果图像大小不同,您将需要一些繁重的渲染自定义,或者可能需要不同的网格框架。
var grid;
var data = [{id: 1, src: 'http://i.stack.imgur.com/Cj07W.jpg?s=128&g=1', txt: 'Some text' }, {id: 2, src: 'https://www.gravatar.com/avatar/4a7ca5a83afc1e7a43bf518ccaa3c9be?s=128&d=identicon&r=PG&f=1', txt: 'Some different text' }];
var columns = [
{id: "id", name: "rowId", field: "id"},
{id: "img", name: "Image", field: "src", formatter: function(args){ return "<span>"+data[args].txt+"</span><br/><img src ='" + data[args].src + "'></img>" }}
];
var options = {
enableCellNavigation: true,
forceFitColumns: true,
rowHeight: 175
};
grid = new Slick.Grid("#myGrid", data, columns, options);
<link rel="stylesheet" type="text/css" href="http://mleibman.github.io/SlickGrid/slick.grid.css">
<link rel="stylesheet" type="text/css" href="http://mleibman.github.io/SlickGrid/css/smoothness/jquery-ui-1.8.16.custom.css">
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="http://mleibman.github.io/SlickGrid/lib/jquery-ui-1.8.16.custom.min.js"></script>
<script src='http://mleibman.github.io/SlickGrid/lib/jquery.event.drag-2.2.js'></script>
<script src='http://mleibman.github.io/SlickGrid/slick.core.js'></script>
<script src='http://mleibman.github.io/SlickGrid/slick.grid.js'></script>
<script src='http://mleibman.github.io/SlickGrid/slick.formatters.js'></script>
<div id="myGrid" style="width:600px;height:500px;"></div>
【讨论】: