PDA

View Full Version : [CLOSED] passing values from one row to another row (related row)



redi
Aug 20, 2014, 4:59 AM
Hello,

I have a gridpanel with add/delete button for inserting/deleting rows. The rows supposed to be interrelated. for example after the add button clicked, the EndTime in the first row should be passed as StartTime in the second rows and so on. Please help me on how to implement this. So far this is my code.



<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" id="igClientScript">

var getRowClass = function (record) {
if (record.phantom) {
return "new-row";
}

if (record.dirty) {
return "dirty-row";
}
};

var insertRecord = function () {
var grid = <%= GridPanel1.ClientID %>;
var total= grid.store.getCount();
grid.store.insert(total, {});
grid.getView().focusRow(total);
grid.editingPlugin.startEdit(grid.store.getAt(tota l), grid.columns[0]);
var sm = grid.getSelectionModel();
sm.select(total);
};
</script>
</head>
<body style="background-color: #DFE8F6">
<form id="form1" runat="server">
<div>
<table align="center" width="98%"><tr><td align="center">
<ext:ResourceManager ID="ResourceManager1" runat="server" Locale="Client" DirectMethodNamespace="ActProduction"/>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<ext:FormPanel
ID="Panel2"
runat="server"
Frame="true"
BodyPadding="10"
Anchor="100% 100%">
<Items>
<ext:GridPanel ID="GridPanel2" runat="server" fittoframe="true" AutoScroll="True" MaxHeight="250">
<topbar>
<ext:Toolbar ID="Toolbar1" runat="server">
<Items>
<ext:Button ID="btnAdd" runat="server" Text="Add" Icon="Add">
<Listeners>
<Click Fn="insertRecord" />
</Listeners>
</ext:Button>
<ext:ToolbarSeparator />
<ext:Button ID="btnDelete" runat="server" Text="Delete" Icon="Exclamation">
<Listeners>
<Click Handler="#{GridPanel2}.deleteSelected(); #{UserForm}.getForm().reset();" />
</Listeners>
</ext:Button>
</Items>
</ext:Toolbar>
</topbar>
<Store>
<ext:Store ID="STR1" runat="server">
<Model>
<ext:Model runat="server" ID="Model1">
<Fields>
<ext:ModelField Name="StartTime" Type="Date" />
<ext:ModelField Name="EndTime" Type="Date" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel2" runat="server" DefaultSortable="false">
<Columns><ext:DateColumn ID="Column1" runat="server" Text="Start Time" DataIndex="StartTime" Width="100" Format="H:i">
<Editor>
<ext:TimeField ID="edStartTime" runat="server" Format="H:i"/>
</Editor>
</ext:DateColumn>
<ext:DateColumn ID="Column2" runat="server" Text="Time End" DataIndex="EndTime" Width="100" Format="H:i">
<Editor>
<ext:TimeField ID="edEndTime" runat="server" Format="H:i"/>
</Editor>
</ext:DateColumn>
</Columns>
</ColumnModel>
<Plugins>
<ext:CellEditing ID="CellEditing4" runat="server" ClicksToEdit="1">
<Listeners>
<BeforeEdit Handler="
if (e.value == null)
e.value = '';">
</BeforeEdit>
</Listeners>
</ext:CellEditing>
</Plugins>
<View>
<ext:GridView ID="GridView2" runat="server" StripeRows="true">
<GetRowClass Fn="getRowClass" />
</ext:GridView>
</View>
</ext:GridPanel>
</ext:FormPanel>
</table>
</div>
</form>
</body>
</html>

Daniil
Aug 20, 2014, 11:58 AM
Hi @redi,

You can iterate all the records and set its values as needed.

store.each(function(record, index)) {
record.set("field name", "new value");
});