Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Need help with listgrid cell icon alignment.

    I have played around with a layout issue we've been meaning to change forever, and i can't get it to work.

    USECASE:
    In a listgrid cell, we are displaying an icon. It is centered in the cell. See example below. We want to be able to align it to the top or the bottom(and left/right) of the inside of the cell, depending on the situation.

    Click image for larger version  Name:	Screen Shot 2020-10-20 at 12.15.19.png Views:	0 Size:	2.1 KB ID:	263864

    PROBLEM:
    I can't get it to work. I'm working with a cell formatter, and i have used Canvas.imgHTML in the past. Now i've tried lots of different stuff - putting my own img code with vertical-alignment, putting a div around with vertical alignment and various other things.

    IT seems that listgrid adds a div around my content called "presentation", which wraps the image, meaning that the height becomes the same as the image. I then hard-coded the height of the div around the img to same as grid, which made the "presentation" div the same as the listgrid cell height and thus the image appeared at the top. But the vertical-alignment doesn't seem to work at all if i instead want the image to appear at the bottom of the cell.

    QUESTION:
    How can i move around a, for example 20X20 image in a cell with height say 100 so that i can control where in the cell it is aligned? Pointers appreciated and test code below:


    Code:
    public void onModuleLoad() {
            ListGrid grid = new ListGrid();
            grid.setCellHeight(70);
            ListGridField id = new ListGridField("id");
            ListGridField name = new ListGridField("name");
            name.setValign(VerticalAlignment.TOP);
            grid.setFields(id, name);
            //name.setCellFormatter((o, listGridRecord, i, i1) -> Canvas.imgHTML("/images/icon.png", 0, 0, "alt", "style='width:20px;height:20px;align:middle;vertical-align:top'", null));
            name.setCellFormatter((o, listGridRecord, i, i1) -> {
                return "<div style='vertical-align:bottom;height:70px;border:1px solid red;' ><img src ='/images/icon.png' style='width:20px;height:20px;align:middle;vertical-align:bottom'/></div >";
            });
            Record data = new Record();
            data.setAttribute("id", "1");
            data.setAttribute("name", "Banana");
            grid.setData(new Record[]{data});
            RootPanel.get().add(grid);
        }

    #2
    Just my 2c, but I think that you'll have to use showRecordComponents and showRecordComponentsByCell to embed a Canvas in the cell.

    Comment


      #3
      The DIV needs to be there because table cells don't clip. Then, because there needs to be a DIV around your content, we go through some very difficult machinations to center the DIV in the cell. What you do inside that DIV won't matter.

      This just means that to fill the cell vertically, your content needs to be as tall as the cell. So you just want to vertically stack the image you intend to align plus a blank image.

      Also bear in mind there is padding on the cell, and you presumably want to keep that (otherwise a bottom aligned image will be flush with a top-aligned image in the next row), so subtract that off when figuring out sizes.

      Comment


        #4
        OK, so let's see if i got this right:

        1. Know the height of the row.

        2. Let's say i want to bottom-align the image. I would then calculate the difference between rowheight and iconheight, and create a black image with that height, and put it above the image i want to align at the bottom.

        3. so if row height is 100, icon height is 25, i would put a blank image, set its height to 75 and then add that on top of the image.

        Comment


          #5
          Yes.

          Comment


            #6
            Worked like a charm (kind of :) ). Thanks!

            Comment

            Working...
            X