PDA

View Full Version : [CLOSED] How can set DateColumn value with Javascript inside grid?



arjunrvasisht
Feb 04, 2015, 8:38 AM
Requirement is on change of date i have to validate the selected date should not be greater than last column date value.
Below is my code


<ext:GridPanel ID="grdDates" runat="server" ButtonAlign="Center"
EnableColumnMove="false">
<Store>
<ext:Store ID="strDates" runat="server" OnReadData="StrDates_OnRefreshData" >
<Model>
<ext:Model IDProperty="MonthId" runat="server">
<Fields>

<ext:ModelField Name="M_Date" Type="Date" DateFormat="yyyy-MM-dd\THH:ss:mm" />
<ext:ModelField Name="C_Date" Type="Date" DateFormat="yyyy-MM-dd\THH:ss:mm" />
<ext:ModelField Name="S_Date" Type="Date" DateFormat="yyyy-MM-dd\THH:ss:mm" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel>
<Columns>

<ext:DateColumn ID="editMDateID" Text="MDate" DataIndex="M_Date" runat="server"
Width="175" Sortable="false" MenuDisabled="true" >
<Editor>
<ext:DateField ID="mDate" runat="server" AllowBlank="true" Editable="true" >
</ext:DateField>
</Editor>

</ext:DateColumn>
<ext:DateColumn ID="editCDateID" Text="Comments Freeze Date" DataIndex="C_Date" runat="server"
Width="175" Sortable="false" MenuDisabled="true" >
<Editor>
<ext:DateField ID="cDate" runat="server" AllowBlank="true" Editable="true" >
</ext:DateField>
</Editor>
</ext:DateColumn>
<ext:DateColumn ID="editSDateID" Text="Snapshot Date" DataIndex="S_Date" runat="server"
Width="175" Sortable="false" MenuDisabled="true" >
<Editor>
<ext:DateField ID="sDate" runat="server" AllowBlank="true" Editable="true" >
</ext:DateField>
</Editor>
</ext:DateColumn>
</Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel runat="server" />
</SelectionModel>
<Plugins >
<ext:CellEditing ID="CellEditing1" runat="server">
<Listeners>
<Edit Fn ="grid_OnEdit"></Edit>
</Listeners>
</ext:CellEditing>
</Plugins>
<View>
<ext:GridView runat="server" MarkDirty="false" StripeRows="true"/>
</View>
</ext:GridPanel>

and below is the function for same


function grid_OnEdit(editor, e) {
debugger;
var mDate =new Date(e.record.data["Metrics_Date"]);
var cDate = e.record.data["Comments_Date"];
var sDate = e.record.data["Snapshot_Date"];
if(sDate < cDate || sDate <mDate)
{
//e.value = null;
//e.setValue(e.originalValue);

}

};

now how to set either original value or clear the value ?

Daniil
Feb 04, 2015, 2:18 PM
Hi @arjunrvasisht,

There is a CellEditing's ValidateEdit even that I would recommend you to use.
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.grid.plugin.CellEditing-event-validateedit