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

Is there a way to change cell/column alignment with client-side code?

2 Answers 55 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 29 Aug 2013, 01:21 PM
I have a situation where I need to be able to modify the text alignment for all the cells in a specific column from left-aligned to right-aligned.  For reasons which are too complicated to go into here, is there a way that I can do this with client-side code?  If the properties to do this are not exposed in the client-side api, is there a css setting that I could modify to do the same thing?  If I had to go the css route I could use jQuery to modify the css at runtime.

Thanks,
Scott

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 30 Aug 2013, 05:08 AM
Hi Scott,

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

0
Scott
Top achievements
Rank 1
answered on 30 Aug 2013, 11:12 AM
Thanks Princy.  This worked for me.
Tags
Grid
Asked by
Scott
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Scott
Top achievements
Rank 1
Share this question
or