This question is locked. New answers and comments are not allowed.
Hi
I am using the Telerik MVC 3 Grid (Telerik.Web.Mvc 2011.1.414.340) with in-line cell editing/batch editing mode. I have two checkbox columns/fields, "AcceptSuggestedValue" and "AcceptOriginalValue", that should behave as two radio buttons would i.e. checking one should uncheck the other. In addition, depending on which checkbox is checked, the text field/column "ActualValue" should be populated with the relevant value from either the "OriginalValue" or "PossibleValue" field/column.
Here is the code for my grid;
I have tried a number of options for obtaining the selected row, and within that row, the various controls so that I may perform comparisons and checks and set values but I haven't had any success yet and I am more confused than ever after searching online and in the forums.
Some of the things I have tried -
As you can see from above I have subscribed to a number of client-side grid events. In the onRowEdit event handler -
although I am able to succesfully modify/set the ActualValue on the dataItem, the change is not reflected in the grid. And besides, this wouldn't help me with toggling the state of the other checkbox, since how would I know which one to toggle?
In terms of toggling the checkbox states, I tried to wire up the client-side onclick event to the individual checkboxes within the ClientTemplate declaration but I couldn't get SetActualValue to fire.
I also tried an example I found that "listens" for the change event of all checkboxes within the grid, as follows;
But there are two issues with this;
I am using the Telerik MVC 3 Grid (Telerik.Web.Mvc 2011.1.414.340) with in-line cell editing/batch editing mode. I have two checkbox columns/fields, "AcceptSuggestedValue" and "AcceptOriginalValue", that should behave as two radio buttons would i.e. checking one should uncheck the other. In addition, depending on which checkbox is checked, the text field/column "ActualValue" should be populated with the relevant value from either the "OriginalValue" or "PossibleValue" field/column.
Here is the code for my grid;
<%= Html.Telerik().Grid<Frontline.ETL.Models.DTO.RuleConflictDTO>() .Name("RuleConflictGrid") .DataKeys(keys => keys.Add(model => model.RuleConflictId)) .Editable(editing => editing.Mode(GridEditMode.InCell)) .Selectable() .ToolBar(commands => { commands.SubmitChanges(); }) .Pageable(paging => paging .PageSize(30) .Style(GridPagerStyles.NextPreviousAndNumeric) .Position(GridPagerPosition.Bottom)) .Columns(columns => { columns.Bound(model => model.UnderlyingTableColumnId).Visible(false); columns.Bound(model => model.QID).Title("QID").ReadOnly(); columns.Bound(model => model.DataRuleName).Title("Rule Name").ReadOnly(); columns.Bound(model => model.UnderlyingFieldName).Title("Field").ReadOnly(); columns.Bound(model => model.Question).Title("Question").ReadOnly(); columns.Bound(model => model.OriginalValue).Title("Original Value").ReadOnly(); columns.Bound(model => model.PossibleValue).ClientTemplate("<#= PossibleValue#>").Width(150); columns.Bound(model => model.AcceptSuggestedValue) .ClientTemplate("<input type='checkbox' name='AcceptSuggestedValue' value='<#= AcceptSuggestedValue #>' />"); columns.Bound(model => model.AcceptOriginalValue) .ClientTemplate("<input type='checkbox' name='AcceptOriginalValue' value='<#= AcceptOriginalValue #>' />"); columns.Bound(model => model.ActualValue).Title("Actual Value").ReadOnly(); }) .ClientEvents(events => events.OnDataBinding("Grid_onDataBinding").OnError("Grid_onError").OnRowSelect("Grid_onRowSelected").OnEdit("Grid_onRowEdit")) .DataBinding(dataBinding => dataBinding.Ajax() .Select("_SelectBatchEditing", "Transform") .Update("_SaveBatchEditing", "Transform") ) %>I have tried a number of options for obtaining the selected row, and within that row, the various controls so that I may perform comparisons and checks and set values but I haven't had any success yet and I am more confused than ever after searching online and in the forums.
Some of the things I have tried -
As you can see from above I have subscribed to a number of client-side grid events. In the onRowEdit event handler -
function Grid_onRowEdit(e) { var dataItem = e.dataItem; dataItem.ActualValue = dataItem.AcceptSuggestedValue ? dataItem.PossibleValue : dataItem.OriginalValue; }although I am able to succesfully modify/set the ActualValue on the dataItem, the change is not reflected in the grid. And besides, this wouldn't help me with toggling the state of the other checkbox, since how would I know which one to toggle?
In terms of toggling the checkbox states, I tried to wire up the client-side onclick event to the individual checkboxes within the ClientTemplate declaration but I couldn't get SetActualValue to fire.
columns.Bound(model => model.AcceptSuggestedValue) .ClientTemplate("<input type='checkbox' name='AcceptSuggestedValue' value='<#= AcceptSuggestedValue #>' onclick='SetActualValue()'/>");I also tried an example I found that "listens" for the change event of all checkboxes within the grid, as follows;
//wire up checkboxes. $('#RuleConflictGrid :checkbox').live('change', function (e) { var myval; var fieldId; var $selectedRows = $("#RuleConflictGrid tr.t-state-selected"); var $check = $(this); var $checkAlt; if (this.name == 'AcceptOriginalValue') { $selectedRows.each(function () { var row = this; var dataItem = $("#RuleConflictGrid").data("tGrid").dataItem(row); //Unsure of how to find the other checkbox in the currently selected row here $checkAlt = row.$find("AcceptSuggestedValue"); }); } else { $selectedRows.each(function () { var row = this; var dataItem = $("#RuleConflictGrid").data("tGrid").dataItem(row); //Unsure of how to find the other checkbox in the currently selected row here $checkAlt = row.$find("AcceptOriginalValue"); }); } //Toggle other checkbox checked state $checkAlt.checked = $check.checked; //Could use similar logic to set ActualValue here //..... });But there are two issues with this;
The row is not set as selected, unless you first select the row and then check the checkbox. I have tried using
-
without any effect.
function Grid_onRowEdit(e) {this.click();} - Also, I cannot find row-specific controls, as I have attempted to and had hoped to (see my comments in the code).
At this stage I am unsure of how to proceed, or which methodology/approach would be best and how to make it work.
Any assistance, advice, pointers to other threads or sample, would be greatly appreciated.
Many thanks!