"set" is undefined for selection in a GridPanel

  1. #1

    "set" is undefined for selection in a GridPanel

    I'm trying to determine how best to port an old Coolite/Ext.Net 0.8.1 web application to Ext.Net 4.x.

    In the existing code, there's a bit that takes some values from a row and updates one value in the selected row's model.

    The original javascript function that gets called uses the following line to update a single value in the selected row (strStatus is either 0 or 1):

    gpOrders.getSelectionModel().getSelected().set("Status", strStatus);
    I've tried a number of variations on this that seem more Ext.NET v4.x-friendly, but they all seem to fail at the same point and insist that "set" is not a valid function. The code I'm testing with now is:

    var selection = App.gpOrders.getSelectionModel().getSelected();
    if (selection) {
        selection.set("Status", strStatus);
    }
    I have verified that I am getting an object in the "selection" variable, so it would appear that something in the syntax has changed and that's not the proper function call today.

    I'm having trouble locating an example in the Ext.Net examples or the ExtJS documentation that tells me what the modern alternative is for this old piece of code.

    The error displayed is:
    0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'set'
    Any pointers would be greatly appreciated!
  2. #2
    Hello, @astovall! Welcome to Ext.NET forums!

    Well, when migrating from a very very old version of Ext.NET like the Coolite one, I'd advise you browsing current version's examples to see how stuff is now done. The Ext.NET documentation and ExtJS documentation are also your friends.

    You may also want to browse Ext.NET v1 examples for correlated examples to see how they changed.

    v1 examples: examples1.ext.net
    v4 examples: examples4.ext.net

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Thanks Fabricio.

    I actually have looked through the earlier version examples. Searching for "set" doesn't get me anything, and as I mentioned, I did look through the ExtJS docs. Struggling with trying to understand how to o something that looks like it ought to be pretty simple. The selectionmodel examples cover a lot of codebehind methods, but don't seem to really cover this.
  4. #4
    Hello again, @astovall!

    What about then, Ext.selection.Model.select()? By them there are also SelectAll() and selectRange().

    We've recently had a discussion involving (beneath a buffered grid selection question) select() that you may just find useful: Header Checkbox is not working properly for Infinite Scroll Grid, specifically post #7.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  5. #5
    After more investigation, it looks like the most common way this is done now is via directevents and directmethods. A little bit of juggling had me change the original buttons with listeners calling javascript functions to buttons with directevents calling methods in the code-behind decorated with [DirectMethod] and an extraparam on each with the button menu item name.

    Here's the final converted version that works (in the code-behind):

            [DirectMethod]
            protected void UpdateStatus(object sender, DirectEventArgs e)
            {
                // Change the Status based on selected Menu Item
                int strStatus = 2; // Shipped
                if (e.ExtraParams["MenuItem"] == "mnuStatusNew") strStatus = 0; // New
                if (e.ExtraParams["MenuItem"] == "mnuStatusSubmit") strStatus = 1; // Submitted
    
                RowSelectionModel sm = gpOrders.SelectionModel.Primary as RowSelectionModel;
                if (sm.SelectedRow != null)
                {
                    SelectedRow sr = sm.SelectedRow;
                    string id = sr.RecordID;
                    gpOrders.GetStore().GetById(id).Set("Status", strStatus);
                }
            }
    So, basically, I won't be doing anything involved in inspection of selectionmodels, etc on the client side.
  6. #6
    Hello @astovall!

    Glad you could find a solution that fits your needs!

    Just as a side advice, it seems you replaced client-side code to a DirectMethod call. DirectMethods or DirectEvents means a server-side call, this means in turn a full round-trip communication to the server.

    If the event is triggered, say, for each row, this can impact a lot in performance. But in the case you show, it looks like is bound to a button click and it will evaluate the whole grid, so you can benefit of the C# typed code over a single round-trip to the server.

    Usually using a Listener means you are handling the task through javascript limited to the client side only, so no round-trips. DirectEvents/Methods will always mean a query to the server.

    Thanks for sharing the solution that worked best for you, by the way, we really appreciate it.
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. [CLOSED] Tooltip on GridPanel CommandColumn displays "undefined"
    By wisdomchuck in forum 1.x Premium Help
    Replies: 3
    Last Post: Apr 10, 2013, 7:39 PM
  2. Replies: 1
    Last Post: Nov 12, 2012, 3:29 PM
  3. Replies: 4
    Last Post: Oct 11, 2011, 3:42 AM
  4. [CLOSED] GridPanel / Renderer : Property "undefined"?
    By wagger in forum 1.x Premium Help
    Replies: 4
    Last Post: May 03, 2011, 9:50 PM
  5. Replies: 14
    Last Post: Apr 12, 2011, 3:49 PM

Tags for this Thread

Posting Permissions