Hello everybody!
I want to add an object in the grid ,with its ID and its name. So I am inspired from the follow link : http://es.infragistics.com/community/forums/p/72892/370474.aspx
What I don't understand, is how to display an object...Here a part of my code (I simplified):
<script>
function fillProductNameLookup(objectToFill) {
var colSettings = $("#grid1").igGridUpdating("option", "columnSettings");
var colSetting;
for (var i = 0; i < colSettings.length; i++) {
colSetting = colSettings[i];
if (colSetting.columnKey === "Product") {
if (colSetting.editorType && colSetting.editorType === "combo") {
var ds = colSetting.editorOptions.dataSource;
var textKey = colSetting.editorOptions.textKey;
var valueKey = colSetting.editorOptions.valueKey;
var item;
for (var j = 0; j < ds.length; j++) {
item = ds[j];
objectToFill[item[valueKey]] = item[textKey];}}
break;}}}
var lookupProductList = {};
fillProductNameLookup(lookupProductList);
function lookupProductName(productNumber) {
return lookupProductList[productNumber];}
</script>
@{
ViewBag.Source = WebSite1.ProductsModel.Get();
}
@(Html.Infragistics().Grid<Model>()
.ID("grid1")
.PrimaryKey("ID")
.RestSettings(rest =>
rest.RestSetting()
.Create(c => c.RestVerbSetting().Url("/api/linea").Batch(true))
.Update(u => u.RestVerbSetting().Url("/api/linea"))
.Remove(r => r.RestVerbSetting().Url("/api/linea"))
)
.Columns(column =>
{
column.For(x => x.ID).Hidden(true);
column.For(x => x.Product ).Width("80px").FormatterFunction("lookupProductName");
})
.Features(features =>
features.Selection().Mode(SelectionMode.Cell).MultipleSelection(true);
features.RowSelectors().EnableCheckBoxes(false).EnableRowNumbering(true);
features.Updating().EditMode(GridEditMode.RowEditTemplate).RowEditDialogContainment("window").EnableAddRow(true).RowEditDialogHeight("700").RowEditDialogWidth("700").RowEditDialogFieldWidth("300")
.ColumnSettings(settings =>
{ settings.ColumnSetting().ColumnKey("Product").EditorType(ColumnEditorType.Combo)
.ComboEditorOptions(options =>
options.ValueKey("IDProduct").TextKey("NameProduct").DataSource(ViewBag.Source);
});
.Height("500px")
.Width("100%")
.DataSourceUrl("/api/linea")
.LocalSchemaTransform(true)
.DataBind()
.Render()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
In the controller class :
public IQueryable<Model> Get()
var pRepositery = new P_Repositery();
var prods = pRepositery.Get();
IEnumerable<Model> prodsM = ToModel(prods);
return prodsM.AsQueryable();
%%%%%%%%%%%%%%%%%
In the model class:
public class Model{
[Display(Name = "ID")]
public int ID{ get; set; }
[Display(Name = "Product")]
public Dictionary<int, string> Product { get; set; }
//OR
//[Display(Name = " Product ")]
//public ProductModel Product { get; set; }
public class ProductModel{
[Display(Name = "IDProduct")]
public int IDProduct { get; set; }
[Display(Name = "Name")]
public Dictionary<int, string> NameProduct { get; set; }
…
Please, tell me what is wrong...At this moment, the grid is well displayed expected products (that are "undefined").
It is the declaration of Product in the class Model? (dictionary<int, string> or ProductModel)?
Best regards,
F2O
Hello F2O,
Thank you for your reply.
Glad to hear that the issue has been resolved. Please do not hesitate to contact me if any related questions regarding this matter arise.
Hello Petar,
I posted the message a month ago and I managed to display the data (I corrected an little error). It works now (based on the sample I indicated).
Thanks,
Hello F20,
In this scenario, is only the Product columns coming as undefined ? If not, I would suggest checking the definition of the datasource action. Should that not be the issue, it may be worth examining the formatter function definition to determine if complex object data is returned there as illustrated at:
http://es.infragistics.com/community/forums/t/65946.aspx
Please do not hesitate to contact me with any updates or questions. A small working sample showing the behavior in practice would be greatly appreciated.