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

Looping Through RadGrids with JavaScript

2 Answers 99 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Turner
Top achievements
Rank 1
Turner asked on 12 May 2017, 03:31 PM

Hello,

I've been using client-side binding for several radgrids on my page. I have a need to clear all of their datasources simultaneously at some points. I want to be elegant and loop through all the grids instead of explicitly clearing them line by line.

I want to do something like this:

var grid = document.getElementsByClassName('SubRadGrid');
$('.SubRadGrid').each(function(){
              
})

 And not like this:

var empty = [];
var grid1 = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
grid1 .set_dataSource(empty);
grid1 .dataBind();
var grid2 = $find("<%= RadGrid2.ClientID %>").get_masterTableView();
grid2 .set_dataSource(empty);
grid2 .dataBind();
var grid3 = $find("<%= RadGrid3.ClientID %>").get_masterTableView();
 grid3 .set_dataSource(empty);
grid3 .dataBind();
Is this possible? Thanks!

2 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 15 May 2017, 01:48 PM

Hi Turner,

You need to access the .control property of the DOM element over which the grid is initialized, this is where the object reference is stored by the MS AJAX framework. You can read more about this here: http://docs.telerik.com/devtools/aspnet-ajax/general-information/get-client-side-reference.

Regards,

Marin Bratanov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Turner
Top achievements
Rank 1
answered on 15 May 2017, 03:21 PM

Hi Marin,

Thanks for your response. That worked great!

Here's my solution for anyone else looking at this:

$('.SubRadGrid').each(function(){
     $(this).get(0).control.get_masterTableView().set_dataSource([]);
     $(this).get(0).control.get_masterTableView().dataBind();
})
Tags
Grid
Asked by
Turner
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Turner
Top achievements
Rank 1
Share this question
or