This is a migrated thread and some comments may be shown as answers.

Client Side OnCommand Cancelling

7 Answers 148 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mula Njira
Top achievements
Rank 1
Mula Njira asked on 18 Feb 2010, 09:44 AM
i am doing my grid binding, sorting, paging client side

i have handled the client side oncommand event like below as an example
 
function radGrid_Command(sender, e) { 
    showloadingpanel(true); 
    e.set_cancel(true); 
    var commandName = e.get_commandName(); 
    switch (commandName) { 
        case 'Sort'
        case 'Page'
        case 'PageSize'
            //if the page has unsaved changes etc etc 
            if (confirm("changes not saved, continue?")){ 
                //pagemethod get my data using the grid pagesize, pageindex, sortcolumn, sort direction, rebind the grid on callback etc etc 
            } 
            else
            //revert the sort, page or pagesize that was changed 
            showloadingpanel(false); 
        default: 
            break
    } 


now it is the else part (reverting the grid to its precommand state) that i need help on

this is what happens in the case of changing the page index

i have a hundred records of page size 10
i am on page 4
i change something somewhere
i change to page 7
on confirm i refuse
result is the page index is still changed to 7 even though i cancelled the event

with sort the sort icon will remain on the previously sorted column (even though i have not allowed multi column sorting)
with pagesize change the new page size will change even though i cancelled


so i guess the question is how do i restore the grid to still select the page 4 that was still selected above or make the sort icon not show on the newly clicked (but sort command cancelled) column? or rever the page size?

thanx

7 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 18 Feb 2010, 01:37 PM
Hello Mula,

OnCommand event after canceling the command you can call set_currentPageIndex to previous one in order to restore RadGrid page visual style:
1.function onCommand(sender, args)
2.{
3.  args.set_cancel(true);               
4.  args.get_tableView().set_currentPageIndex(0);                
5.}

However the value of previous page index will have to be manually tracked.

Sincerely yours,
Nikolay
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Mula Njira
Top achievements
Rank 1
answered on 18 Feb 2010, 01:59 PM
thanx for the reply, i have a way of tracking that + previous pagesize, even the sortcolumn (fieldName) and sort direction

so i guess page size and page number can be pretty straight forward but it is the sorting that is somewhat the most important and maybe most complicated

i can reset the sortExpressions.getItem(0) fieldname and sortdirection but having them restored is where i think the main question is

as it stands now previous "sorts" with their sort icons still get shown and all, it would be really helpful if there was a resetSortIcons property or hack or something :-)


0
Mula Njira
Top achievements
Rank 1
answered on 18 Feb 2010, 02:14 PM
ooops just noticed that both commands

args.get_tableView().set_currentPageIndex(0); 
 
args.get_tableView().set_pageSize(0); 

results in the oncommand event being fired twice (which kinda makes sense but still...)

so, other than via some flag, is there a way to have change revert these properties without firing the changed event? (oncommand that is)

but this is not as important as the reverting of the sortexpression...

thanx



0
Nikolay Rusev
Telerik team
answered on 22 Feb 2010, 12:23 PM
Hello Mula,

You can use the following approach to revert sort expressions:
1.function on_Command(sender, args)
2.            {
3.                  
4.                args.set_cancel(true);
5.                  
6.                args.get_tableView().set_currentPageIndex(0, true);                
7.                args.get_tableView()._showSortIconForField("Title", Telerik.Web.UI.GridSortOrder.None);
8.            }

It will change sort indicators for column appear depending the sort order. Regarding double fire of onCommand you can call set_currentPageIndex with second parameter which indicates whether to call onCommand or not. By default it is false and command will be call. 

All the best,
Nikolay
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Mula Njira
Top achievements
Rank 1
answered on 08 Mar 2010, 03:39 PM
Hi Nikolay,
sorry couldn't get back to you earlier...
the
args.get_tableView().set_currentPageIndex(0, true);                  
tip worked out greatly but there seems to be some issue with regards to using
args.get_tableView()._showSortIconForField("Title", Telerik.Web.UI.GridSortOrder.None);  
in that the icon doesnt get hidden...

inspecting the markup with IE Developer tools shows that a style="display: none;" has been added to the markup for the icon but it still shows... :(

completely stumped on this, hope you have more insight

Thanx in advance :)

Mula



0
Accepted
Nikolay Rusev
Telerik team
answered on 11 Mar 2010, 08:25 AM
Hello Mula,

_showSortIconForField approach works perfectly on my end. Other option is to use the code bellow:
01.function hideSortIndicators(tableId, fieldName)
02.        {
03.            var id1 = String.format("{0}__{1}__SortAsc", tableId, fieldName);
04.            var id2 = String.format("{0}__{1}__SortDesc", tableId, fieldName);
05.  
06.            if ($get(id1))
07.            {
08.                $get(id1).style.display = "none";
09.            }
10.            if ($get(id2))
11.            {
12.                $get(id2).style.display = "none";
13.            }
14.        }

and use it within OnCommand handler as follow:
1.hideSortIndicators(args.get_tableView().get_id(), "Unique ID");


Best wishes,
Nikolay
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Mula Njira
Top achievements
Rank 1
answered on 11 Mar 2010, 05:00 PM
hi Nikolay,

that works :)

thanx
Tags
Grid
Asked by
Mula Njira
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Mula Njira
Top achievements
Rank 1
Share this question
or