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

RadGrid Column Background Color Change

4 Answers 621 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jamil
Top achievements
Rank 1
Jamil asked on 28 Apr 2010, 10:18 PM
Hello,

is there a way to accomplish the following task using the RadGrid client side API:

RadGridComparableAnalysis.MasterTableView.AutoGeneratedColumns[columnCounter].ItemStyle.BackColor =

Color.White;

 


As you can noticed from the following code, i'm able to get the object of target column but could not find a property which can allow me to change the background color. Please let me know what i'm missing here

//Define array of columns

 

var grdColumns = new Array(masterTable.get_columns().length);

 

//Get all columns
grdColumns = masterTable.get_columns();

 


//Navigate to all columns and chage background color for the required columns
for
(var columnCounter = 0; columnCounter < masterTable.get_columns().length; columnCounter++) {

 

 

var remainder = (columnCounter % 2);

 

 

if (remainder == 0) {

 

 

var grdColumn = grdColumns[columnCounter];

 

 

//masterTable.getColumnByUniqueName(grdColumn.get_uniqueName()).backColor = "Blue";
//masterTable.autoGeneratedColumns[columnCounter].itemStyle.iackColor = "Blue";
}
}

 

Thanks

 

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 29 Apr 2010, 08:27 AM
Hello Jamil,

Here is the sample code that I tried, to change the background color of a particular column from client side.

JavaScript:
 
    function ButtonClick() { 
        var grid = $find("<%=RadGrid1.ClientID %>"); 
        var MasterTable = grid.get_masterTableView(); 
        var length = MasterTable.get_dataItems().length; 
        for (var i = 0; i < length; i++) { 
            MasterTable.get_dataItems()[i].get_cell("ColumnUniqueName").style.backgroundColor = "red"
            MasterTable.get_dataItems()[i].get_cell("ColumnUniqueName").style.backgroundImage = "none"
        } 
    } 

Regards,
Shinu.
0
DCoop
Top achievements
Rank 1
answered on 25 Jun 2020, 04:00 PM

Received the following from example code

Error: Unable to get property 'style' of undefined or null reference

function ApplyButton() {

 

 var grid = $find("<%=RadGrid2.ClientID %>");
            var MasterTable = grid.get_masterTableView();
            var length = MasterTable.get_dataItems().length;
            for (var i = 0; i < length; i++) {
                MasterTable.get_dataItems()[i].get_cell("ColumnUniqueName").style.backgroundColor = "red";
                }
        }

1
DCoop
Top achievements
Rank 1
answered on 25 Jun 2020, 04:13 PM

Shinu,

I see the issue.  What I need is all column changes, not a specific column. Please advise.

 

 

 

0
Attila Antal
Telerik team
answered on 30 Jun 2020, 12:31 PM

Hi DCoop,

The exception "Error: Unable to get property 'style' of undefined or null reference" indicates that the element or object "MasterTable.get_dataItems()[i].get_cell("ColumnUniqueName")" does not exist it is null or undefined. Having that in mind, it is possible that a Column with the UniqueName "ColumnUniqueName" does not exist and the get_cell("ColumnUniqueName") returns null or undefined.

Please double-check that to ensure the code is calling the correct references. 

For more information about accessing items, cell or value in RadGrid using the client-side API, please check out the following articles:

Kind regards,
Attila Antal
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
Grid
Asked by
Jamil
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
DCoop
Top achievements
Rank 1
Attila Antal
Telerik team
Share this question
or