Rebind on item expand (and how to "reset" insert and edit before expanding)

5 posts, 0 answers
  1. Massimiliano
    Massimiliano avatar
    184 posts
    Member since:
    Oct 2012

    Posted 20 Nov 2013 Link to this post

    I'm facing two issues with my current implementation of a radgrid wich uses nestedviewtemplates to show details inside multipage + formviews.
    1)- First issue is that when expanding an item, even if viewstate is enabled, it seem the grid still calls the needdatasource and launch the db query. Why? Is this correct? I'm just expanding a row shouldn't it retrieve the rest of the current grid page from the controlstate/viewstate?
    2)- Second issue is that... I'm using InPlace edit for the grid rows, also I'm using the grid <EditFormSettings EditFormType="Template"> for insert. What happens now is that if I have InPlace editing active on a row and I expand another row (or the same one) things get messed up with JS errors. And the same happens when the insert is active. If I do the other way round (with one or more rows expanded I go to edit InPlace or launch Insert) everything works correct since it seems that before entering InPlace or Insert the grid is rebound and all the expanded rows are closed.

    Those 2 questions are somehow related since... to solve the second issue I would like to obtain on item expand the same "effect" that happens automatically when you go InPlace edit or Insert, but it seems that the grid already rebinds itself when you expand an item.

    I'm a bit confused and need some help here. I solved now with a trick on client command that way: <ClientEvents OnCommand="CheckExpand" /> 
    And in the JS code:
    // Check if edit InPlace or Insert is active before expanding grid and rebind
    function CheckExpand(sender, eventArgs) {
        if (eventArgs.get_commandName() == "ExpandCollapse") {
            var masterTable = sender.get_masterTableView();
            var item = masterTable.get_dataItems()[eventArgs.get_commandArgument()];
            var isexpand = item.get_expanded()
            var editItems = masterTable.get_editItems();
            var insertItem = masterTable.get_insertItem();
     
            if ((editItems.length > 0 || insertItem != null) && isexpand == false) {
                masterTable.fireCommand("RepaintGrid", "");
            }
        }
    }

    RepaintGrid just issues a grid.MasterTableView.Rebind()

    But this is not working as intended since it ALWAYS does a rebind even when edit inplace or insert are not active. Infact I have HierarchyLoadMode="Conditional" but each time I expand or collapse a row grid is always rebind. Positive side is that it actualluy
    Good news is that this fixes the issues when inplace or insert are active and I expand a grid since it "resets" the grid first removing them and then expand the row BUT in this scenario a double rebind happens (see problem number 1 above) and this is not good.

    Need some help here. Thank you in advance for your usual support both Telerik staff and helpful users!
    This community is great and is great to contribute somehow even with problems that when resolved are useful to anyone.
  2. Massimiliano
    Massimiliano avatar
    184 posts
    Member since:
    Oct 2012

    Posted 22 Nov 2013 Link to this post

    I had some time to dig a bit deeper in the issue and found this: it seems that if you add onCommand in ClientEvents of RadGrid, even if you do nothing in the JS function that is called, just adding it raises a roundtrip to server and execution of the .aspx page on each click you do in whatever place in the grid.
    So even if you for example just want to hide a DIV with JS on each click on the grid, if you try to do it with the onCommand client event you always fire the aspx page with roundrip to server.
    This thing is quite obscure since is an handler for JS events and it should only trigger roundtrips if the actual click on the grid does.
    Let's check the first obvious condition  that comes to my mind. When you set HierarchyLoadMode to conditional (my scenario depitched above), expanding or collapsing rows only happens to the client but if you ad onCommand then it always goes to server even if it has nothing to do server side.

    I wonder if there is a way for example to apply eventArgs.preventDefault() to the onCommand event WHEN the row will be expanded client side since it has already been loaded, exploiting the conditional HierarchyLoadMode wich otherwise becomes useless just because I added an onCommand listener.
    This is about issue (1)

    Also any suggestion on how to solve issue (2) in a better and more performant way are welcome


  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 25 Nov 2013 Link to this post

    Hello Massimiliano,

    Regarding the OnCommand issue. Now when RadGrid has an event handler attached to the OnCommand event the grid prepares itself for client-side data-binding. Moreover operations like expand/collapse in this case are done by executing a command using the fireCommand method of the MasterTableView. That said the behavior experienced is expected. Note that canceling the default execution is not recommended because it will prevent the expand/collapse of the items.

    As for the other issue it seems that you are trying to use two different types of EditModes at the same time. This is not supported and in order to achieve such an effect you should change the EditMode on the server and rebind the grid.

    Please provide us with a detail explanation of the requirements and scenario you are after so we could review them and advice you with the best possible option.

    Regards,
    Angel Petrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  5. Massimiliano
    Massimiliano avatar
    184 posts
    Member since:
    Oct 2012

    Posted 25 Nov 2013 Link to this post

    Thank you Angel for your answer as usual.
    This is what I supposed. Considering that this is working how is intended, my first requirement would be to exploit the benefit of having HierarchyLoadMode set to "conditional" for nested items, while at the same time firing some JS functions in the onCommand event.
    This means avoiding the roundtrip to the server if the row has already been expanded, otherwise HierarchyLoadMode conditional would give no benefit just because I'm executing some JS events in the onCommand event (for example I'm resetting some JS alerts each time the user clicks on any command on the grid).

    This is the first scenario and it's just "performance optimization" nothing  critical, so if you think an implementation would become too complex, it's not important.

    About the second scenario it's very odd because I'm just using one edit mode in the grid (the inplace one) or eventually the insert, but for all the updates I use formviews with their edit modes but the grid row (expanded) remains in read mode.


     
  6. Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 28 Nov 2013 Link to this post

    Hi Massimiliano,

    As I mentioned in my previous post when a handler is attached to the OnCommand event a command will be executed and a round trip to the server will occur for every expand/collapse. If you want to avoid this behavior and execute some JavaScript after the initial expand I suggest that you remove the OnCommand handler and subscribe to the OnHierarchyExpanded or OnHierarchyCollapsed events. By following this approach you will be able to both optimize the performance and execute additional client-side logic.

    For the second problem however I would like to ask you to share with us the markup and code-behind so we could investigate further.

    Regards,
    Angel Petrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017