PDA

View Full Version : [CLOSED] GridPanel : Grid with AutoSave Date not insert in grid



matrixwebtech
May 19, 2015, 7:49 PM
I do bellow code but the date not show in grid after click add


<script>
var addRecordtoGridPFNomination = function (form, grid) {
if (!form.getForm().isValid()) {

return false;
}
console.log(form.getForm().getValues());
grid.store.insert(0, new Model_PFNomination(form.getForm().getValues()));
form.getForm().reset();
};


</script>
@( X.FormPanel()
.Border(true)
.Title("Nominee")
.BodyStyle("background-color: #F1F1F1;")
.Items(
X.FieldSet()
.Border(false)
.ColumnWidth(0.4)
.Items(
X.FieldContainer().Layout(LayoutType.HBox)
.Items
(
X.DateField()
.ID("NomineeDateofBirth")
.Name("NomineeDateofBirth")
.FieldLabel("Date of Birth")
.AnchorHorizontal("100%")
.Format("dd-MM-yyyy")
.LabelAlign(LabelAlign.Right)
)
,
X.GridPanel()
.ID("GridPFNomination")
.Scroll(ScrollMode.Both)
.ColumnWidth(1.0)
.AutoScroll(true)
.Height(150)
.SetAutoScroll(true)
.Store
(
X.Store()
.ID("Store_PFNomination")
.Model
(
X.Model()
.Name("Model_PFNomination")
.IDProperty("EmployeeNomineeID")
.Fields
(
X.ModelField()
.Name("NomineeDateofBirth")
.ServerMapping("NomineeDateofBirth")
.Type(ModelFieldType.Date)
.DateFormat("dd-MM-yyyy")
)
)


)
.ColumnModel
(


X.DateColumn()
.DataIndex("NomineeDateofBirth")
.Text("Date of Birth")
.Sortable(false)
.MenuDisabled(true)
.Resizable(false)
.Width(100)
.Format("dd-MM-yyyy")

)
.Listeners(l => l.SelectionChange.Handler = @"if (selected[0])
{
this.up('form').getForm().loadRecord(selected[0]);
}"
)

)

)
.Buttons(

Html.X().Button()
.Text("Add")
.Icon(Icon.UserAdd)
.Handler(@"addRecordtoGridPFNomination(this.up('form'), App.GridPFNomination)"),

Html.X().Button()
.Text("Reset")
.Handler("this.up('form').getForm().reset();")
)

)

Daniil
May 19, 2015, 10:51 PM
Hi @matrixwebtech,

I just tried your code and it appears working to me.

I do:

1. Pick some date in the DateField
2. Click the Add button
3. The new row appears with the picked up date shown

matrixwebtech
May 20, 2015, 3:53 AM
Hi
I try again steps you follow , but not working .I use
FF 35.0.1 and 38.0.1
Chrome 42.0.2311.152 m

may be this will help you for suggest any thing. I try


console.log(form.getForm().getValues());

23984

Date format of date field and date format of the object in firebug console are different.so is that a problem?

After click on add a blank row is insert in grid

23986

matrixwebtech
May 21, 2015, 9:37 AM
any thought ? what's going wrong in my case?I stuck in middle of development of a very vital screen.

matrixwebtech
May 22, 2015, 7:56 AM
I am give some more images of my local machine date formats may be this is help you for better understanding
23992
23993
23994

matrixwebtech
May 22, 2015, 11:40 AM
Hi
I change the javascript function and format the date as d-m-Y and insert in model manually and its working , but my question is why previous code not working for me?


var addRecordtoGridPFNomination = function (form, grid) {
if (!form.getForm().isValid()) {

return false;
}
var d = form.getForm().getValues().NomineeDateofBirth

console.log(d)
d=Ext.Date.format(new Date(d),'d-m-Y')
console.log(d)
// grid.store.insert(0, new Model_PFNomination(form.getForm().getValues()));
grid.store.insert(0, new Model_PFNomination({ NomineeDateofBirth: d }));
form.getForm().reset();
};

Daniil
May 22, 2015, 11:58 AM
Please try to add this to your initial code that is not working.

.SubmitFormat("dd-MM-yyyy")

matrixwebtech
May 22, 2015, 12:03 PM
thanks a lot,

.SubmitFormat("dd-MM-yyyy") is working also. so previous submitted date format different because of my local machine's date format?

Daniil
May 22, 2015, 2:02 PM
so previous submitted date format different because of my local machine's date format?

Yes, OS's locale settings might affect a default value of a DateField's SubmitFormat.

matrixwebtech
May 22, 2015, 5:56 PM
again I faced a problem I load the grid with proxy which return "NomineeDateofBirth":"2015-05-22T00:00:00" which is not displayed in grid

I set datecolumn

X.DateColumn()
.DataIndex("NomineeDateofBirth")
.Text("Date of Birth")
.Sortable(false)
.MenuDisabled(true)
.Resizable(false)
.Width(100)
.Format("dd-MM-yyyy")
Model as


X.ModelField()
.Name("NomineeDateofBirth")
.ServerMapping("NomineeDateofBirth")
.Type(ModelFieldType.Date)
.DateFormat("dd-MM-yyyy")

I try http://forums.ext.net/showthread.php?27802-CLOSED-Custom-null-date-value-in-gridpanel&p=123756&viewfull=1#post123756 ,and when grid load via proxy the date show but when I try to add a date on click Add not working .

matrixwebtech
May 23, 2015, 4:37 AM
Please see the example , I not use Convert in Model.


<script>
var addRecordtoGridPFNomination = function (form, grid) {
if (!form.getForm().isValid()) {

return false;
}
console.log(form.getForm().getValues());
grid.store.insert(0, new Model_PFNomination(form.getForm().getValues()));
form.getForm().reset();
};


</script>
@( X.FormPanel()
.Border(true)
.Title("Nominee")
.BodyStyle("background-color: #F1F1F1;")
.Items(
X.FieldSet()
.Border(false)
.ColumnWidth(0.4)
.Items(
X.FieldContainer().Layout(LayoutType.HBox)
.Items
(
X.DateField()
.ID("NomineeDateofBirth")
.Name("NomineeDateofBirth")
.FieldLabel("Date of Birth")
.AnchorHorizontal("100%")
.Format("dd-MM-yyyy")
.LabelAlign(LabelAlign.Right)
.SubmitFormat("dd-MM-yyyy")
)
,
X.GridPanel()
.ID("GridPFNomination")
.Scroll(ScrollMode.Both)
.ColumnWidth(1.0)
.AutoScroll(true)
.Height(150)
.SetAutoScroll(true)
.Store
(
X.Store()
.ID("Store_PFNomination")
.Model
(
X.Model()
.Name("Model_PFNomination")
.IDProperty("EmployeeNomineeID")
.Fields
(
X.ModelField()
.Name("NomineeDateofBirth")
.ServerMapping("NomineeDateofBirth")
.Type(ModelFieldType.Date)
.DateFormat("dd-MM-yyyy")
)
)
.Proxy(Html.X().AjaxProxy()
.Url(Url.Action("loadgrid"))
.Reader(Html.X().JsonReader().Root("data")))

)
.ColumnModel
(


X.DateColumn()
.DataIndex("NomineeDateofBirth")
.Text("Date of Birth")
.Sortable(false)
.MenuDisabled(true)
.Resizable(false)
.Width(100)
.Format("dd-MM-yyyy")

)
.Listeners(l => l.SelectionChange.Handler = @"if (selected[0])
{
this.up('form').getForm().loadRecord(selected[0]);
}"
)

)

)
.Buttons(

Html.X().Button()
.Text("Add")
.Icon(Icon.UserAdd)
.Handler(@"addRecordtoGridPFNomination(this.up('form'), App.GridPFNomination)"),

Html.X().Button()
.Text("Reset")
.Handler("this.up('form').getForm().reset();")
)

)


public ActionResult loadgrid()
{
dob _dob = new dob();
_dob.NomineeDateofBirth = Convert.ToDateTime("5/22/2015 12:00:00 AM");
return this.Store(_dob);
}

public class dob
{
public DateTime NomineeDateofBirth { get; set; }
}

23999

this Post (http://forums.ext.net/showthread.php?19787-CLOSED-Date-Trouble&p=85269&viewfull=1#post85269) is Helpful .

Daniil
May 26, 2015, 5:18 PM
It is nice to see you found out the solution! And thank you for sharing that!