Trying to change column width in table

Ranorex Studio, Spy, Recorder, and Driver.
kewpiedoll99
Posts: 8
Joined: Wed May 20, 2015 9:13 pm

Trying to change column width in table

Post by kewpiedoll99 » Wed Jun 17, 2015 9:24 pm

I have a table created dynamically and every row's cells have the width spec'd. I'm trying to change the width in the 17th column but it's not changing. Here's the code I'm using:

Code: Select all

string tdRxPathBase = "/dom/body/div[1]/table/tbody/tr[1]";
string tdRxPath = tdRxPathBase + "/td[17]";
TdTag eTdTag = null;
Host.Local.TryFindSingle(tdRxPath, 10000, out eTdTag);
eTdTag.MoveTo();
eTdTag.SetStyle("width","10");
When I execute I can see ranorex moving to the cell, but the width does not change. Do I need to iterate over all the rows and change it in each one?

kewpiedoll99
Posts: 8
Joined: Wed May 20, 2015 9:13 pm

Re: Trying to change column width in table

Post by kewpiedoll99 » Wed Jun 17, 2015 9:35 pm

FYI, I changed my code to iterate over all rows and change the 17th column's width in each row, but it did not end up with a changed width at the end of the iteration. Please help. The app I am testing has an overflow=hidden, such that when a column does not show the button that button is unclickable.

ALSO, this is a web application, not a windows form. Thanks all.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Trying to change column width in table

Post by Support Team » Thu Jun 18, 2015 8:57 am

Hello kewpiedoll99,

It depends on how your TD tag look like. For example:
<td width="1" j="" style="width: 1px;">MyTD</td>
If you want to set the CSS style attribute “width” please use the following code:

Code: Select all

eTdTag.SetStyle("width", "700px");
If you want to set the TD tag width, please use this code:

Code: Select all

eTdTag.Width = "700";
Hope this helps.

Regards,
Robert

kewpiedoll99
Posts: 8
Joined: Wed May 20, 2015 9:13 pm

Re: Trying to change column width in table

Post by kewpiedoll99 » Thu Jun 18, 2015 3:28 pm

Thanks for the clarification on which to use. The width of my TD tags are set using style attribute, but not the width attr. I noticed that there is in each an inner div that also has a width set (using the style attr):

Code: Select all

<td class="v-table-header-cell" style="width: 83px;">
    <div class="v-table-resizer"></div>
    <div class="v-table-sort-indicator"></div>
    <div class="v-table-caption-container v-table-caption-container-align-left" style="width: 69px;">Categories</div>
</td>
So I changed my code to change the style/width of both td and inner div. However, the changes are not taking effect when the code runs - the col width stays the same.

Code: Select all

    Host.Local.TryFindSingle(hdrTdRxPath, 1000, out hdrTd);
    hdrTd.MoveTo();
    hdrTd.Class = "";
    hdrTd.SetStyle("width","10");
    DivTag innerHdrDiv = null;
    Host.Local.TryFindSingle(hdrTdRxPath + "/div[3]", 1000, out innerHdrDiv);
    innerHdrDiv.Class = "";
    innerHdrDiv.SetStyle("width","10");
Edited to add: I even tried changing the class to "" on the elements I'm trying to change. This is the resulting html, which I can see change as the code runs:

Code: Select all

<td class="" style="width: 83px;">
    <div class="v-table-resizer"></div>
    <div class="v-table-sort-indicator"></div>
    <div class="" style="width: 69px;">Categories</div>
</td>
As you can see the style does not change. Do I need to call some additional method on the TdTag or on the DivTag to make the changes stick? What am I doing wrong?

kewpiedoll99
Posts: 8
Joined: Wed May 20, 2015 9:13 pm

Re: Trying to change column width in table

Post by kewpiedoll99 » Thu Jun 18, 2015 3:49 pm

I got it - I needed to include "px" in my width measurement. Without it, it was failing to replace the existing setting. With px, the width changed to my setting and I saw the display change as well.

Code: Select all

    hdrTd.SetStyle("width","10px");