我有我设置的这个模型:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace aSa.Web.Scheduling.Models
{
public class Trailer
{
[Key]
public int TrailerKey { get; set; }
public string TrailerID { get; set; }
public string TrailerDesc { get; set; }
public string FabLocID { get; set; }
public double MaxWgt { get; set; }
public int TrailerImgKey { get; set; }
}
}
我为它设置了一个带有实体框架的 Web API 2 OData 控制器。我正在使用这个控制器中的 odata 来填写我的IgniteUI igGrid。这是我对这个网格的设置:
$('#gridTrailers').igGrid({
odata: true,
autoGenerateColumns: false,
autoGenerateLayouts: true,
responseDataKey: 'value',
dataSource: clientDS,
updateUrl: '/odata/Trailers',
primaryKey: 'TrailerKey',
width: '100%',
height: '500',
enableCheckBoxes: true,
columns: [
{ headerText: 'Trailer Key', key: 'TrailerKey', dataType: 'string', width: '100px' },
{ headerText: 'Trailer ID', key: 'TrailerID', width: '200px' },
{ headerText: 'Description', key: 'TrailerDesc', width: '100px' },
{ headerText: 'FabLocID', key: 'FabLocID', width: '100px' },
{ headerText: 'Max Weight', key: 'MaxWgt', width: '100px' },
{ headerText: 'Trailer', key: 'TrailerImgKey', width: '100px' },
],
features:
[
{
name: 'Sorting',
type: 'local'
},
{
advancedModeEditorsVisible: true,
name: 'Filtering',
caseSensitive: false,
type: 'local', //I think this can be local now
//mode: 'advanced',
FilterExprUrlKey: 'filter',
columnSettings: [
{ columnKey: 'TrailerKey', allowFiltering: false },
{ columnKey: 'TrailerImgKey', allowFiltering: false }
]
},
{
name: 'ColumnMoving'
},
{
mouseDragSelect: false,
multipleSelection: true,
touchDragSelect: false,
name: 'Selection',
},
{
editMode: 'cell',
startEditTriggers: 'dblclick',
name: 'Updating',
enableAddRow: true,
enableDeleteRow: true
},
{
name: 'Resizing'
},
{
name: 'Hiding'
}
],
});
目前,我正在使用一个旧数据库,该数据库的 TrailerImageKey 与特定图片相关,该图片将在此应用程序的旧版本中从另一个数据库加载。我现在在我的项目中有一个名为“TrailerImages”的文件夹。我目前正在尝试找到一种方法来设置网格的最后一列以显示基于 TrailerImageKey 的特定预告片图像。
我知道我在这里设置专栏:
columns: [
{ headerText: 'Trailer Key', key: 'TrailerKey', dataType: 'string', width: '100px' },
{ headerText: 'Trailer ID', key: 'TrailerID', width: '200px' },
{ headerText: 'Description', key: 'TrailerDesc', width: '100px' },
{ headerText: 'FabLocID', key: 'FabLocID', width: '100px' },
{ headerText: 'Max Weight', key: 'MaxWgt', width: '100px' },
{ headerText: 'Trailer', key: 'TrailerImgKey', width: '100px' },
],
我想知道是否可以执行以下操作:
{ headerText: 'Trailer', key: 'TrailerImgKey', width: '100px', dataType: "object",
template: "<img width='100' height='90' src={{>val}}></img>", formatter: function(val){
switch(TrailerImageKey) {
case 1:
val = 'C:\Source_Code\Web\MyApp\TrailerImages\RedTrailer.png'
break;
case 2:
val = 'C:\Source_Code\Web\MyApp\TrailerImages\RedTrailer.png'
break;
default:
val = ''
}
}
},
我觉得我接近正确的想法,但对 IgniteUI 和基础设施相当不熟悉,并且难以让它发挥作用。如果有人对我如何根据我的 Odata 中的 TrailerImageKey 将图像加载到我的 igGrid 有任何建议,我将不胜感激。