Hey I currently have the following code which I have used to generate a grid model within the controller class for my page:
private GridModel GetGridModel(IEnumerable<TimelineViewModel> timelineVMs) { var model = new TimelineViewModel();
GridModel gridModel = new GridModel(); gridModel.ID = "gridModel"; gridModel.AutoGenerateColumns = false; gridModel.AutoGenerateLayouts = false; gridModel.PrimaryKey = "ID"; gridModel.LoadOnDemand = false; gridModel.Width = "100%"; gridModel.Columns = new List<GridColumn>() { new GridColumn() { HeaderText = model.GetDisplayName(nameof(TimelineViewModel.ID)), Key = nameof(TimelineViewModel.ID), DataType = "string", Width = "5%", Hidden = true}, new GridColumn() { HeaderText = model.GetDisplayName(nameof(TimelineViewModel.EquipmentType)), Key = nameof(TimelineViewModel.EquipmentType), DataType = "string", Width = "10%"}, new GridColumn() { HeaderText = model.GetDisplayName(nameof(TimelineViewModel.SubType)), Key = nameof(TimelineViewModel.SubType), DataType = "string", Width = "10%" }, new GridColumn() { HeaderText = model.GetDisplayName(nameof(TimelineViewModel.CurrentInstallation)), Key = nameof(TimelineViewModel.CurrentInstallation), DataType = "string", Width = "10%" }, new GridColumn() { HeaderText = model.GetDisplayName(nameof(TimelineViewModel.StartDate)), Key = nameof(TimelineViewModel.StartDateString), DataType = "string", Width = "15%" }, new GridColumn() { HeaderText = model.GetDisplayName(nameof(TimelineViewModel.EndDate)), Key = nameof(TimelineViewModel.EndDateString), DataType = "string", Width = "15%" }, new GridColumn() { HeaderText = model.GetDisplayName(nameof(TimelineViewModel.DayRate)), Key = nameof(TimelineViewModel.DayRate), DataType = "string", Width = "10%" }, new GridColumn() { HeaderText = model.GetDisplayName(nameof(TimelineViewModel.ClientPONumber)), Key = nameof(TimelineViewModel.ClientPONumber), DataType = "string", Width = "20%" }, new GridColumn() { HeaderText = model.GetDisplayName(nameof(TimelineViewModel.WebConfirmed)), Key = nameof(TimelineViewModel.WebConfirmed), DataType = "string", Width = "10%" }, };
gridModel.DataSourceUrl = this.Url.Action("GetCategoriesData"); gridModel.DataSource = timelineVMs.AsQueryable();
gridModel.Features.Add(new GridHiding()); gridModel.Features.Add(new GridFiltering() { Type = OpType.Local, Inherit = true, Persist = false }); gridModel.Features.Add(new GridSorting() { Type = OpType.Local, Inherit = true, Persist = false }); gridModel.Features.Add(new GridPaging() { Type = OpType.Local, Inherit = true, PageSize = 5 }); gridModel.Features.Add(new GridResponsive() { EnableVerticalRendering = false, });
return gridModel; }
I was wondering what code needs to be added to allow certain columns to be editable, the documentation on this particular issue seems to be somewhat lacking (as i can only find samples of making columns editable when the grid is created within the view / the only sample of code that shows how to generate a grid within the controller doesn't mention anything about adding the ability to edit columns).cheers!
Hello Callum,
I see. Let me know if you have further questions regarding this subject.
Best regards,Martin PavlovInfragistics, Inc.
Hey Martin thank you for the reply.Due to the lengthy amount of time it took to get a response I decided to rebuild the grid within the view where the edit functionality is now working.
From what I understand you're unable to enter edit mode in all cases.
The client side error: "infragistics.lob.js:500 Uncaught Error: The specified record or property was not found. Verify the criteria for your search and adjust them if necessary." explains that and is most probably caused by a data type mismatch between the primary key data type and the declared data type of the column when declared in the columns collection. In the column collection you declare the "ID" column as string, so the data should be string as well.
Can you send me the output of the following JavaScript please.
JSON.stringify($("#gridModel").data("igGrid").options);
Thanks in advance,Martin PavlovInfragistics, Inc.
[bump]
Hey Tsanna thank you for the reply.Unfortunately this code hasn't made any of the cells within the columns editable.I have noticed that when looking at the 'EditMode' property of the GridUpdating object I can see that EditMode is throwing an exception of type System.ArgumentException.
In addition I have noticed that when clicking on one of the cells the following error occurs: "infragistics.lob.js:500 Uncaught Error: The specified record or property was not found. Verify the criteria for your search and adjust them if necessary."
After having no success with the code that you suggested I have tried a few other things and my code now looks like this:
GridUpdating updating = new GridUpdating(); updating.EnableAddRow = false; updating.EnableDeleteRow = false; updating.EditMode = GridEditMode.Cell;
ColumnUpdatingSetting colSettingInstallation = new ColumnUpdatingSetting(); ColumnUpdatingSetting colSettingClientPONumber = new ColumnUpdatingSetting(); ColumnUpdatingSetting colSettingDayRate = new ColumnUpdatingSetting(); ColumnUpdatingSetting colSettingWebConfirmed = new ColumnUpdatingSetting();
colSettingInstallation.ColumnKey = nameof(TimelineViewModel.CurrentInstallation); colSettingClientPONumber.ColumnKey = nameof(TimelineViewModel.ClientPONumber); colSettingDayRate.ColumnKey = nameof(TimelineViewModel.DayRate); colSettingWebConfirmed.ColumnKey = nameof(TimelineViewModel.WebConfirmed);
colSettingInstallation.ReadOnly = false; colSettingClientPONumber.ReadOnly = false; colSettingDayRate.ReadOnly = false; colSettingWebConfirmed.ReadOnly = false;
colSettingClientPONumber.EditorType = ColumnEditorType.Text; colSettingDayRate.EditorType = ColumnEditorType.Currency; colSettingWebConfirmed.EditorType = ColumnEditorType.Checkbox;
updating.ColumnSettings.Add(colSettingInstallation); updating.ColumnSettings.Add(colSettingClientPONumber); updating.ColumnSettings.Add(colSettingDayRate); updating.ColumnSettings.Add(colSettingWebConfirmed);
gridModel.Features.Add(updating);
The only thing that seemed to happen once editing was added to the grid was that I was able to remove or add columns, if you could me towards any examples of editing being added to gridmodels within the controller that would be extremely helpful!cheers!