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

Align column to right using javascript

1 Answer 14 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ryann
Top achievements
Rank 1
Ryann asked on 01 Oct 2013, 07:29 AM

Hi..
Is it possible to align a column to right using javascript.someone please help.

Thanks,
Ryann. 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 01 Oct 2013, 07:32 AM
Hi Ryann,

Please try the following code snippet to get a column cell text to be right aligned using JS.

ASPX:
<ClientSettings>
    <ClientEvents OnGridCreated="OnGridCreated" />
</ClientSettings>

JS:
<script type="text/javascript">
    function OnGridCreated() {
        var colIndex;
        var grid = $find("<%=RadGrid1.ClientID %>");
        var MasterTable = grid.get_masterTableView();
        var Rows = MasterTable.get_dataItems();
        for (var i = 0; i < Rows.length; i++) {
            var col = Rows[i].get_cell("ColumnUniqueName");
            col.style.textAlign = "right"; //to align the cells of column
            colIndex = col.cellIndex; //to get the cell index
        }
        MasterTable.HeaderRow.cells[colIndex].style.textAlign = "right"; // to align the header text
    }
</script>

Thanks,
Princy
Tags
Grid
Asked by
Ryann
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or