PDA

View Full Version : [CLOSED] Grid Error



adelaney
Aug 01, 2012, 2:18 PM
I am using a grid in an MVC (Razor) app with the rowEditing plugin. On the first page, there is no problem with editing. However, on other pages, when going into edit mode, I receive this error:

"context is undefined"

The debugger points me to this source:

if (me.beforeEdit(context) === false || me.fireEvent('beforeedit', me, context) === false || context.cancel || !me.grid.view.isVisible(true)) {
return false;
}

(here's a broader look)

beforeEdit: Ext.emptyFn,
startEdit: function(record, columnHeader) {
var me = this,
context = me.getEditingContext(record, columnHeader);
if (me.beforeEdit(context) === false || me.fireEvent('beforeedit', me, context) === false || context.cancel || !me.grid.view.isVisible(true)) {
return false;
}
me.context = context;
me.editing = true;
},

I do have listeners on the rowEditing plugin, but I don't have a "BeforeEdit." I am retrieving the data via a proxy, but I have remote paging set to false, so I am unsure why editing on page 2-n would be any different than page 1.

Any ideas or hints as to why this error is presenting?

Daniil
Aug 01, 2012, 3:17 PM
Hi,

I am unable to reproduce. Please provide a test sample.

adelaney
Aug 01, 2012, 4:49 PM
I have a bit more detail which may help.

I have a column in the grid with buttons. One of the buttons fires off the editing command. The script for that is:


function gridCommandClick(caller, row) {
App.TeamGrid.editingPlugin.startEdit(row.index, 0);

That fails. However, simply double-clicking the row works. Am I calling the startEdit incorrectly?

adelaney
Aug 01, 2012, 5:15 PM
I have a bit more information...

In my function, I pass the row.index. If I view that number, it may be 33. When I then do something like:

App.TeamGrid.store.getAt(33)
, I received an "undefined." Further, I see that even though I may be on page 2 and on row #36, the "getAt" may wind up being 2. This isn't at all what I would have expected. In fact, even though my store has 406 records, if I "getAt" anything larger than my page size index(currently pagesize=15) I receive "undefined." However, if I use:

App.TeamGrid.store.allData.getAt(row.index)
, I do get the correct row, but I don't know how to translate that to the rowEditing pluging to edit the actual row I am on in the grid. Hopefully, this is making sense.

Daniil
Aug 01, 2012, 7:29 PM
The getAt method expects an index within the current page.

The startEdit method expects a record (not index) and a column to be passed as the arguments.
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.grid.plugin.RowEditing-method-startEdit

adelaney
Aug 02, 2012, 2:22 PM
I have reviewed the link. I don't know how I came upon the original javascript, but it was somewhere searching throught the forum or examples. At any rate, the link was helpful except it wasn't clear about the "column" part (the page has "columnheader" which is really confusing). Here is the code I landed on:

App.TeamGrid.editingPlugin.startEdit(App.tmStore.a llData.getAt(row.index), 0);

So far, it seems to work. I did try passing in my "column" (App.teamName), but the script balked at that. However, the column index seems like it works. Still, if there is something better (or more accurate) that I should be doing, please let me know. Other than that, we can mark the thread closed.


Thanks.

Daniil
Aug 02, 2012, 4:13 PM
I have discovered that the startEdit method can apply indexes for the both arguments. Just it's not documented.

So, the following works:

editingPlugin.startEdit(0, 0);

The second "column" argument means a column editor which will be initially focused in the row editor.

adelaney
Aug 02, 2012, 4:38 PM
So, the following works:

Code:
1 editingPlugin.startEdit(0, 0);
The second "column" argument means a column editor which will be initially focused in the row editor

Be careful with that, because that is what was giving me an issue and prompted this thread. The code above DOES work for a grid with no pagination or a paginated grid on page 1. It breaks on grids pages 2-n. It seems that the reason why is because the index on page 2, row 3 (as an example) is not necessarily the index of the store record. I think you need the index of the store record in order for this to actually work.

Daniil
Aug 02, 2012, 4:52 PM
Please clarify what is the "row" here?

function gridCommandClick(caller, row)

adelaney
Aug 02, 2012, 5:58 PM
Sure. "Row" is passed via a listener from a command button:


Dim btn2 As New Ext.Net.GridCommand()
With btn2
.Text = "Cedents"
.Icon = Icon.None
.CommandName = "ManageCedents"
.StandOut = True
End With

commands.Add(btn2)
End Sub).Listeners(Sub(lstnrs)
lstnrs.Command().Handler = "gridCommandClick(command,record);"
End Sub) _


Actually, passing "row" in instead of row.index does work, but as stated, the example for the rowEditing I found had indicies. When, I was tracing through the issue, the row.index value I was getting was the index of the row(record) as it pertains to its position on a given page. So, on an item on page 2, row 3, the index would return 2. However, what I needed to pass (given a pageSize of 20) was 21 (at least that is what I am assuming will work).

Daniil
Aug 02, 2012, 7:02 PM
Yes, this

record.index
returns an index through all pages.

But you should pass the current page index into the startEdit method.

.Command().Handler = "gridCommandClick(command, record, recordIndex);"


function gridCommandClick (command, record, recordIndex) {
grid.getRowEditor().startEdit(recordIndex, 0);
}