当另一个更改客户端时,Telerik RadGrid设置单元格值

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了当另一个更改客户端时,Telerik RadGrid设置单元格值相关的知识,希望对你有一定的参考价值。

我有一个RadGrid,其中某些列处于批量编辑模式。我还有两列依赖于另一个值(EstLengthFt和EstLengthRds)。我需要在编辑EstLengthFt单元格时更新EstLengthRds值,反之亦然。我只更新html而不是值的当前函数。我需要更新控件的值并将其设置为BatchEditChanged模式,以便我可以保存它。

我不能做任何回发,因为编辑的值会丢失。

任何帮助将不胜感激!

    function AllSetCellValue(sender, args) {
                var grid;
                var master;
                var selected;
                var row;
                var ft;
                var cell;
                var rods;
                if (args.get_columnUniqueName() == "EstLengthFt") {
                    grid = $find('<%=RadGridAll.ClientID%>');
                    master = grid.get_masterTableView();
                    selected = master.get_selectedItems();
                    row = selected[0];
                    ft = args.get_value();
                    cell = master.getCellByColumnUniqueName(row, "EstLengthRds");
                    rods = Math.round((ft * .060606060606) * 100) / 100;
                    cell.innerHTML = rods;
                }
                if (args.get_columnUniqueName() == "EstLengthRds") {
                    grid = $find('<%=RadGridAll.ClientID%>');
                    master = grid.get_masterTableView();
                    selected = master.get_selectedItems();
                    row = selected[0];
                    rods = args.get_value();
                    cell = master.getCellByColumnUniqueName(row, "EstLengthFt");
                    ft = Math.round((rods * 16.5) * 100) / 100;
                    cell.innerHTML = ft;
                 }
            }

<telerik:RadGrid runat="server" ID="RadGridAll" AllowMuliRowEdit="True" AllowMultiRowSelection="True" AllowSorting="True"
                GridLines="None" AllowFilteringByColumn="True" AllowMultiRowEdit="True" OnNeedDataSource="GridAll_NeedDataSource"
                OnBatchEditCommand="GridAll_BatchEditComand" AllowPaging="True" PageSize="20" EnableLinqExpressions="False"
                OnHTMLExporting="GridAll_HTMLExporting">
                <MasterTableView DataKeyNames="PropId,RowDetailsId,SurveyId,TitleInitId,TitleSumId" CommandItemDisplay="None"
                    AllowAutomaticUpdates="False" AllowAutomaticInserts="False" AllowAutomaticDeletes="False"
                    AutoGenerateColumns="False" TableLayout="Fixed" EditMode="Batch">
                    <BatchEditingSettings EditType="Cell" OpenEditingEvent="Click" />
                    <Columns>
                        <telerik:GridBoundColumn DataField="PropertyNumber" HeaderText="Tract Number" ReadOnly="True" HeaderStyle-Width="140px"
                            FilterControlWidth="100px" />
                        <telerik:GridBoundColumn DataField="IndexNumber" HeaderText="Index Number" ReadOnly="True" HeaderStyle-Width="120px"
                            FilterControlWidth="80px" />
                        <telerik:GridBoundColumn DataField="DisplayName" HeaderText="Type" ReadOnly="True" HeaderStyle-Width="140px"
                            UniqueName="DisplayName">
                            <FilterTemplate>
                                <telerik:RadComboBox runat="server" Width="130px" EmptyMessage="All" AutoPostBack="True"
                                    OnSelectedIndexChanged="GridPropTypeFilter_SelectedIndexChanged" EnableLoadOnDemand="True"
                                    OnItemsRequested="GridPropTypeCombo_ItemsRequested" AppendDataBoundItems="True" />
                            </FilterTemplate>
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="OwnerName" HeaderText="Owner Name" ReadOnly="True" HeaderStyle-Width="140px"
                            FilterControlWidth="100px" />
                        <telerik:GridTemplateColumn DataField="EstLengthFt" HeaderText="Est ROW Length(ft)" HeaderStyle-Width="100px"
                            FilterControlWidth="60px" ConvertEmptyStringToNull="True" UniqueName="EstLengthFt">
                            <ItemTemplate>
                                <%#Eval("EstLengthFt") %>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadNumericTextBox runat="server" ID="txtEstLengthFt" Type="Number" NumberFormat-DecimalDigits="2"/>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn DataField="EstLengthRds" HeaderText="Est ROW Length(rds)" HeaderStyle-Width="100px"
                            FilterControlWidth="60px" ConvertEmptyStringToNull="True" UniqueName="EstLengthRds">
                            <ItemTemplate>
                                <%#Eval("EstLengthRds") %>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadNumericTextBox runat="server" ID="txtEstLengthRds" Type="Number" NumberFormat-DecimalDigits="2" />
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn DataField="Name" HeaderText="Address" HeaderStyle-Width="200px"
                            FilterControlWidth="160px" ReadOnly="True" />
                        <telerik:GridBoundColumn DataField="Legal" HeaderText="Legal Description" HeaderStyle-Width="170px"
                            FilterControlWidth="130px" ReadOnly="True" />
                        <telerik:GridBoundColumn DataField="Status" HeaderText="Status" ReadOnly="True" HeaderStyle-Width="120px"
                            FilterControlWidth="80px" ConvertEmptyStringToNull="True" />
                        <telerik:GridTemplateColumn UniqueName="PermWidthDd" DataField="PermWidthDd" HeaderText="Perm Width(ft)" HeaderStyle-Width="100px"
                            FilterControlWidth="60px">
                            <ItemTemplate>
                                <%#Eval("PermWidthDd") %>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadComboBox runat="server" ID="cmbGridPermitFt"
                                    DataTextField="DDName" DataValueField="DDValue" Width="90px" EnableLoadOnDemand="True"
                                    OnItemsRequested="GridPermitCombo_ItemsRequested" />
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn HeaderText="Temp Width(ft)" HeaderStyle-Width="100px"
                            FilterControlWidth="60px" UniqueName="TempWidthDd">
                            <ItemTemplate>
                                <%#Eval("TempWidthDd") %>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadComboBox runat="server" ID="cmbGridTemFt"
                                    DataTextField="DDName" DataValueField="DDValue" Width="90px" EnableLoadOnDemand="True"
                                    OnItemsRequested="GridTempCombo_ItemsRequested" />
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridDateTimeColumn DataField="TractClosedDate" HeaderText="Tract Closed" HeaderStyle-Width="170px"
                            FilterControlWidth="130px" PickerType="DatePicker" EmptyDataText=""
                            DataFormatString="<%$ Resources:WebResources,dateFormatGrid %>" />
                        <telerik:GridBoundColumn DataField="ServiceProviderName" HeaderText="Company Assigned" HeaderStyle-Width="170px"
                            FilterControlWidth="130px" ReadOnly="True" />
                        <telerik:GridDateTimeColumn DataField="SurveyAssigned" HeaderText="Survey Assigned Date" HeaderStyle-Width="170px"
                            FilterControlWidth="130px" PickerType="DatePicker" EmptyDataText="" ReadOnly="True"
                            DataFormatString="<%$ Resources:WebResources,dateFormatGrid %>" />
                        <telerik:GridDateTimeColumn DataField="SurveyPermDate" HeaderText="Permission Date" HeaderStyle-Width="170px"
                            FilterControlWidth="130px" PickerType="DatePicker" EmptyDataText=""
                            DataFormatString="<%$ Resources:WebResources,dateFormatGrid %>" />
                        <telerik:GridDateTimeColumn DataField="FieldWorkCompleteDate" HeaderText="Field Work Completed" HeaderStyle-Width="170px"
                            FilterControlWidth="130px" PickerType="DatePicker" EmptyDataText=""
                            DataFormatString="<%$ Resources:WebResources,dateFormatGrid %>" />
                        <telerik:GridDateTimeColumn DataField="FinalPlatRecvdDate" HeaderText="Final Plat Received" HeaderStyle-Width="170px"
                            FilterControlWidth="130px" PickerType="DatePicker" EmptyDataText=""
                            DataFormatString="<%$ Resources:WebResources,dateFormatGrid %>" />
                        <telerik:GridDateTimeColumn DataField="CreatedDate" HeaderText="Title Work Assigned" HeaderStyle-Width="170px"
                            FilterControlWidth="130px" PickerType="DatePicker" EmptyDataText="" ReadOnly="True"
                            DataFormatString="<%$ Resources:WebResources,dateFormatGrid %>" />
                        <telerik:GridBoundColumn HeaderText="Title Status" DataField="StatusDd" HeaderStyle-Width="170px"
                            FilterControlWidth="130px" ReadOnly="True" />
                        <telerik:GridDateTimeColumn DataField="DateLtcCompleted" HeaderText="Title Completed" HeaderStyle-Width="170px"
                            FilterControlWidth="130px" PickerType="DatePicker" EmptyDataText=""
                            DataFormatString="<%$ Resources:WebResources,dateFormatGrid %>" />
                        <telerik:GridBoundColumn DataField="TitleAgent" HeaderText="Title Agent Assigned" HeaderStyle-Width="170px"
                            FilterControlWidth="130px" ReadOnly="True" />
                        <telerik:GridDateTimeColumn DataField="AgentAssignedDate" HeaderText="Agent Assigned Date" HeaderStyle-Width="170px"
                            FilterControlWidth="130px" PickerType="DatePicker" EmptyDataText="" ReadOnly="True"
                            DataFormatString="<%$ Resources:WebResources,dateFormatGrid %>" />
                    </Columns>
                </MasterTableView>
                <ClientSettings Selecting-AllowRowSelect="True">
                    <ClientEvents OnBatchEditSetCellValue="AllSetCellValue" />
                    <Scrolling AllowScroll="True" FrozenColumnsCount="2" UseStaticHeaders="True" SaveScrollPosition="True" />
                </ClientSettings>
            </telerik:RadGrid>
答案

看一下BatchEditingManager提供的客户端API,看看你是否可以把它放在一起:http://www.telerik.com/help/aspnet-ajax/grid-batch-editing.html。本文的第三部分处理客户端API。

另一答案

我能够通过在我的comboBox模板列中使用OnValueChanging事件来解决这个问题。我还添加了两个隐藏的列来存储原始值,以便我可以进行比较并确定哪个单元格已更改。唯一的问题是当值更改时,comboBox再次触发OnValueChanging事件并创建一个连续循环。我在更改值后为comboBox添加了一个.Set标志以防止这种情况发生。以下代码解决了我的问题。

function AllConvertValue(sender, args) {
        var grid = $find('<%=RadGridAll.ClientID%>');
        var master = grid.get_masterTableView();
        var getRow = master.get_selectedItems()[0];
        var row = master.get_dataItems()[getRow._itemIndex];
        var cellFt = row.findControl("txtEstLengthFt");
        var cellRds = row.findControl("txtEstLengthRds");
        var oldFt = row.findControl("OldFtValue");
        var oldRds = row.findControl("OldRdsValue");
        if (cellFt != null && cellRds != null) {
            if (oldFt._value != cellFt._value) {
                var rods = (cellFt._value * 0.060606061).toFixed(2);
                if (cellRds.Set != true) {
                    cellRds.Set = true;
                    cellRds.set_value(rods);
                }
                if (oldRds.Set != true) {
                    oldRds.Set = true;
                    oldRds.set_value(cellRds._value);
                }
                if (cellFt.Set != true) {
                    cellFt.Set = true;
                    cellFt.set_value(cellFt._value);
                }
                if (oldFt.Set != true) {
                    oldFt.Set = true;
                    oldFt.set_value(cellFt._value);
                }
            }
            if (oldRds._value != cellRds._value) {
                var ft = (cellRds._value * 16.500033).toFixed(2);
                if (cellFt.Set != true) {
                    cellFt.Set = true;
                    cellFt.set_value(ft);
                }
                if (oldFt.Set != true) {
                    oldFt.Set = true;
                    oldFt.set_value(cellFt._value);
                }
                if (cellRds.Set != true) {
                    cellRds.Set = true
                    cellRds.set_value(cellRds._value);
                }
                if (oldRds.Set != true) {
                    oldRds.Set = true;
                    oldRds.set_value(cellRds._value);
                }
            }
            if (oldFt._value == cellFt._value && oldRds._value == cellRds._value) {
                cellFt.Set = false;
                cellRds.Set = false;
                oldFt.Set = false;
                oldRds.Set = false;
            }
        }
    }


<telerik:RadGrid runat="server" ID="RadGridAll" AllowMuliRowEdit="True" AllowMultiRowSelection="True" AllowSorting="True"
            GridLines="None" AllowFilteringByColumn="True" AllowMultiRowEdit="True" OnNeedDataSource="GridAll_NeedDataSource"
            OnBatchEditCommand="GridAll_BatchEditComand" AllowPaging="True" PageSize="20" EnableLinqExpressions="False"
            OnHTMLExporting="GridAll_HTMLExporting">
            <MasterTableView DataKeyNames="PropId,RowDetailsId,SurveyId,TitleInitId,TitleSumId" CommandItemDisplay="None"
                AllowAutomaticUpdates="False" AllowAutomaticInserts="False" AllowAutomaticDeletes="False"
                AutoGenerateColumns="False" TableLayout="Fixed" EditMode="Batch">
                <BatchEditingSettings EditType="Row" OpenEditingEvent="Click" />
                <Columns>
                    <telerik:GridBoundColumn DataField="PropertyNumber" HeaderText="Tract Number" ReadOnly="True" HeaderStyle-Width="120px"
                        FilterControlWidth="80px" MaxLength="50" />
                    <telerik:GridBoundColumn DataField="IndexNumber" HeaderText="Index Number" ReadOnly="True" HeaderStyle-Width="110px"
                        FilterControlWidth="70px" MaxLength="50" />
                    <telerik:GridBoundColumn DataField="DisplayName" HeaderText="Type" ReadOnly="True" HeaderStyle-Width="140px"
                        UniqueName="DisplayName" MaxLength="50">
                        <FilterTemplate>
                            <telerik:RadComboBox runat="server" Width="130px" EmptyMessage="All" AutoPostBack="True"
                                OnSelectedIndexChanged="GridPropTypeFilter_SelectedIndexChanged" EnableLoadOnDemand="True"
                                OnItemsRequested="GridPropTypeCombo_ItemsRequested" AppendDataBoundItems="True" />
                        </FilterTemplate>
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="OwnerName" HeaderText="Owner Name" ReadOnly="True" HeaderStyle-Width="140px"
                        FilterControlWidth="100px" MaxLength="50" />
                    <telerik:GridTemplateColumn DataField="EstLengthFt" HeaderText="Est ROW Length(ft)" HeaderStyle-Width="140px"
                        FilterControlWidth="100px" ConvertEmptyStringToNull="True" UniqueName="EstLengthFt">
                        <ItemTemplate>
                            <%#Eval("EstLengthFt") %>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <telerik:RadNumericTextBox runat="server" ID="txtEstLengthFt" Type="Number" MaxLength="50" Width="130px"
                                ClientEvents-OnValueChanged="AllConvertValue" />
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn DataField="EstLengthFt" UniqueName="OldFtValue" Display="False">
                        <ItemTemplate>
                            <telerik:RadNumericTextBox runat="server" ID="OldFtValue" Type="Number" ReadOnly="True"
                                ClientEvents-OnValueChanged="AllConvertValue" Text='<%#Bind("EstLengthFt") %>' />
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn DataField="EstLengthRds" HeaderText="Est ROW Length(rds)" HeaderStyle-Width="140px"
                        FilterControlWidth="100px" ConvertEmptyStringToNull="True" UniqueName="EstLengthRds">
                        <ItemTemplate>
                            <%#Eval("EstLengthRds") %>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <telerik:RadNumericTextBox runat="server" ID="txtEstLengthRds" Type="Number" MaxLength="50" Width="130px"
                                ClientEvents-OnValueChanged="AllConvertValue" />
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn DataField="EstLengthRds" UniqueName="OldRdsValue" Display="False" ReadOnly="True">
                        <ItemTemplate>
                            <telerik:RadNumericTextBox runat="server" ID="OldRdsValue" Type="Number"
                                ClientEvents-OnValueChanged="AllConvertValue" Text='<%#Bind("EstLengthRds") %>' />
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn DataField="Name" HeaderText="Address" HeaderStyle-Width="200px"
                        FilterControlWidth="160px" ReadOnly="True" MaxLength="50" />
                    <telerik:GridBoundColumn DataField="Legal" HeaderText="Legal Description" HeaderStyle-Width="170px"
                        FilterControlWidth="130px" ReadOnly="True" MaxLength="50" />
                    <telerik:GridBoundColumn Data

以上是关于当另一个更改客户端时,Telerik RadGrid设置单元格值的主要内容,如果未能解决你的问题,请参考以下文章

当另一个进程对文本文件进行更改时,C# 会收到通知

当另一个 div 悬停时更改一个 div 的文本颜色

当另一个片段中的数据发生更改时,如何刷新一个片段中的 RecyclerView

当另一个子div悬停时,更改子div的外观

当另一个客户端发送到服务器时,如何让 UDP 服务器推送到客户端

如何在客户端为 Telerik 组合框设置路由值