I thought that I created a workaround for this. I added a function to be called after the action of saving is completed. It looks like this:
function ActionCompleted(args) {
if (args.requestType == "save") {
var gridObj = $("#MultiplesImputacionesGrid").data("ejGrid");
gridObj.refreshContent();
}
}
But it DOESN'T WORK. It does a real mess. When I click the last row (the second row), the value of the cell change itself to the value of the top cell (the first row) and when I edit that second row, it actually edits the cell of the first row.
Refreshing the grid content doesn't help. This is a real mess!! OMG haven't anyone reported this??
Ok I investigated more and I think I found the reason why it doesn't work for me, even if I define a primary key. Understanding why, is even more frustrating.
First, I needed new rows to be added at the bottom of the grid, not above. Suggested by you in this thread, I have the following .js code that is the workaround and to the job:
if (args.requestType == "save") {
this.model.dataSource.shift();// Remove the newly added record from first position
this.model.dataSource.push(args.data)// Push the newly added record in data source
this.refreshContent();
}
Now, that does the job of putting rows at the bottom of the grid when they are saved, but that code is also the problem why I can't edit in my grid properly, even if I add a primary key. If I just comment or remove that code, adding a primary key resolves the problem of not been able to edit correctly.
Again, I can edit if I add the primary key to the grid, but only if I delete the code that I need for the rows to be moved at the bottom of the grid when saved. Damn, what should I do so BOTH THINGS work properly??? Little bit frustrated here. Help!
Thank you
Sooooooooooooo?? Someone is kinda desperate here!
Thank you!
I solved everything with some logic. I have some threads alive in this forum searching for ways to do some things. This codes resumes everything working well. I needed to add some custom logic to it in order to work properly.
var RecordJustAdded = false;
var InfraccionData = [
{ id: "Primera", text: "Primera" },
{ id: "Segunda", text: "Segunda" },
{ id: "Tercera", text: "Tercera" },
{ id: "Cuarta", text: "Cuarta" },
{ id: "Quinta", text: "Quinta" },
{ id: "Sexta", text: "Sexta" },
{ id: "Septima", text: "Séptima" },
{ id: "Octava", text: "Octava" },
{ id: "Novena", text: "Novena" },
{ id: "Decima", text: "Décima" }
];
function ActionBegin(args) {
if (args.requestType == "save") {
if (RecordJustAdded) {
var index = this.model.dataSource.length - 1;
if (index == -1) {
args.data.InfraccionId = 1;
}
else {
args.data.InfraccionId = this.model.dataSource[index].InfraccionId + 1
}
}
}
else if (args.requestType == "cancel") {
RecordJustAdded = false
}
}
function ActionCompleted(args) {
if (args.requestType == "add") {
$("#" + this._id + "Infraccion").ejDropDownList({
dataSource: InfraccionData,
field: { text: "text", value: "text" },
width: "100%"
});
RecordJustAdded = true;
}
if (args.requestType == "save" && RecordJustAdded) {
this.model.dataSource.shift();// Remove the newly added record from first position
this.model.dataSource.push(args.data)// Push the newly added record in data source
this.refreshContent();
RecordJustAdded = false;
}
}
Please refer to this thread in order to understand what that "RecordJustAdded" variable does.
@(Html.EJ().Grid<object>("FlatGrid")
.Datasource((IEnumerable<object>)ViewBag.datasource)
.AllowSorting()
.AllowPaging()
-----------------------------
.Columns(col =>
{
----------------------
})
)
<script>
var RecordJustAdded = false;
var InfraccionData = [
{ id: "Reims", text: "Reims" },
{ id: "Lyon", text: "Lyon" },
{ id: "Charleroi", text: "Charleroi" },
{ id: "Bern", text: "Bern" },
{ id: "Resende", text: "Resende" },
{ id: "UK", text: "UK" },
{ id: "USA", text: "USA" },
{ id: "Berlin", text: "Berlin" },
{ id: "Belgium", text: "Belgium" },
{ id: "Graz", text: "Graz" }
];
function begin(args) {
if (args.requestType == "save" && this.element.find(".gridform").parents("tr").hasClass("e-addedrow")) {
var index = this.model.dataSource.length - 1;
args.data.OrderID = this.model.dataSource[index].OrderID + 1;
RecordJustAdded = true;
}
}
function complete(args) {
if (args.requestType == "add") {
$("#" + this._id + "ShipCity").ejDropDownList({
dataSource: InfraccionData,
field: { text: "text", value: "text" },
width: "100%"
});
}
if (args.requestType == "save" && RecordJustAdded) {
this.model.dataSource.shift();// Remove the newly added record from first position
this.model.dataSource.push(args.data)// Push the newly added record in data source
this.refreshContent();
RecordJustAdded = false;
}
}
</script> |