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

Client side radgrid handle row selection by edit link in the row

3 Answers 222 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mac P
Top achievements
Rank 1
Mac P asked on 25 Apr 2011, 12:57 AM
Hello

My RadGrid is based on following demo.
http://demos.telerik.com/aspnet-ajax/grid/examples/client/insertupdatedelete/defaultcs.aspx
There is no server side events or server side bindings.

It is functional but i want to do following things

  • I have template columns with edit, delete and other link. When i insert a new row and rebind and repaint on client side the links are not rendered for newly inserted row.
  • Enable row selection Edit link click that is a template column inside grid

   and disable row selection on row click

For all above if i get row object than i can work with it.

I am doing following thing. That works but how to disable row selection? I have onrowselecting event and there i check for eventargs dom to cancel for td but it is throwing an error in the event when i select from below. is there an efficient way?

 

 

 

 

 

And in function i have following code

<telerik:GridTemplateColumn
<ItemTemplate>  
  
 <a href="#" onclick="EditPersonClick('<%#DataBinder.Eval(Container.DataItem, "PersonId")%> 
  
','Person');return false;"> 
Edit
</a
 </ItemTemplate
  
 </telerik:GridTemplateColumn>

 

 

 

function EditPersonClick(personId) { 
var grid = $find(Person_GridFollowUp); 
var masterTable = grid.get_masterTableView(); 
var dataItems = masterTable.get_dataItems(); 
if (dataItems!=null && dataItems.length > 0) { 
for (var i = 0; i < dataItems.length; i++) { 
  
var dbPersonId= dataItems[i].getDataKeyValue("PersonId" 
  
); // primary key 
if (dbPersonId== personId) { 
var row = dataItems[i]; 
row.set_selected(true); 
return
}}}}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 28 Apr 2011, 09:49 AM
Hello Mac,

Here is an example how you can cancel the row selection:

<ClientEvents OnRowSelecting="RowSelecting" />

function RowSelecting(sender, args)
{
if(!
confirm('select?'))
args.set_cancel(true);
}

Additionally, to select row by edit link you can handle the ItemCreated event and find the Edit link. Then consider intercepting the OnClientClick event of the link button and pass the index of the clicked record inside the OnClientClick handler. Thus you will be able to select the grid row in the same manner.

I hope this helps.

Regards,
Pavlina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Mac P
Top achievements
Rank 1
answered on 29 Apr 2011, 04:00 AM
Thanks palvina for reply.

The issue is that i am able to select the row using link click but i am unable to disable selection on row click

First code snippet is ongridrowselecting and second code snippet is when i select the row by link click.
function ongridrowselecting(sender, args) {
                       var e = args.get_domevent(); 
                     //NOTE: When selected by link click it throws an exception as e.srcelement is undefined.
                       alert(e.srcelement);
                       //ie - srcelement, others - target
                       var targetelement = e.srcelement || e.target;
                        
                       if (targetelement != 'undefined') {
                           if (targetelement.tagname && targetelement.tagname != 'undefined') {
                               if (targetelement.tagname == 'td') {
                                   args.set_cancel(true);
                               }                
                           }
                       }
       }

function editClick(myid) {
            var grid = $find(mygrid);
            var masterTable = grid.get_masterTableView();
            var dataItems = masterTable.get_dataItems();
  
            if (dataItems != null && dataItems.length > 0) {
                for (var i = 0; i < dataItems.length; i++) {
                    var dbid= dataItems[i].getDataKeyValue("MyId");
                    if (dbid== myid) {
                        var row = dataItems[i];
                        row.set_selected(true);
                        return;
                    }
                }
  
            }
        }
0
Pavlina
Telerik team
answered on 02 May 2011, 01:07 PM
Hello Mac,

The code library shows how to achieve the required functionality.
ClientSideSelectColumn - Disallow other selection

Regards,
Pavlina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Mac P
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Mac P
Top achievements
Rank 1
Share this question
or