Announcement

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

    ListGrid with custom control in cells

    SmartGWT version: 3.0.0 nightly from 11/23

    I'm wondering what the the corret way to put a custom control in a ListGrid cell? The grid is backed by a data source that is being updated in the background. The cells containing the custom controls need to update when the datasource data backing the cell is updated in the data source.

    Following the showcase sample, I tried overriding the createRecordComponent method to place my widget in the cell (calling the base class implementation of createRecordComponent for the other non-custom columns in the grid).

    This seems to have some issues that makes me think it is not the correct way to go about this.

    First of all, the text data in the data source that is used to back the cell shows as intermixed with my custom control content (I solved this by using a cell formatter to "transform" the content to an empty string). This seems like a hack to me.

    More problematic is handling updates to the data source. When fields in the record are updated in the data source, the createRecordComponent method gets called for all of the columns EXCEPT the one where I returned a custom canvas originally for my custom cell. Therefore, the cell does not update when data source value changes.

    I'm looking for direction on the correct way to implement a custom control in a grid cell backed by changing data. I'm willing to consider using a different grid control if ListGrid is not the correct choice.

    #2
    First, see the ListGrid Editing overview. If you're trying to do inline editing and you just want to customize on cell's editor, use setEditorType() to do it in harmony with this system.

    "createRecordComponent" is mostly for other types of controls, which may be additive to the content, underneath it, opaque, etc - hence the default content is not hidden. Components created with "createRecordComponent" can interact with the editing system as well, via setEditValue() and the other APIs explained in the ListGrid Editing overview.

    Comment


      #3
      This is a read-only grid (no editing capability). Is a custom editory type still the right way to go when I'm trying to provide custom display in the non-edit mode?

      Comment


        #4
        For just customized read-only display there are ton of available APIs, with samples for each: CellFormatter, getCellCSSStyle/Text, valueIcons, etc. Be more specific with what you are trying to do.

        Comment


          #5
          I am trying to put a bar graph in the cell with each bar representing an ink level (bar color is same as ink color) and height indicating the % available. As the level of ink available changes over time, the data source value backing the cell changes and I want to redraw the graph in that cell.

          Comment


            #6
            This is a good use for recordComponents assuming your bar graph is going to be instance of FacetChart or similar. You can wipe out the content as you've done via a CellFormatter, or leave it there and just ensure your chart is opaque. See also recordComponentPosition.

            As far as this effect:

            More problematic is handling updates to the data source. When fields in the record are updated in the data source, the createRecordComponent method gets called for all of the columns EXCEPT the one where I returned a custom canvas originally for my custom cell. Therefore, the cell does not update when data source value changes.
            .. this is correct behavior, due to pooling. Read the extensive overview of the system under showRecordComponents - this is linked pervasively from recordComponent-related APIs.

            Comment


              #7
              OK, that brings me back to my original issue. What is the recommended way to get the graph to update? I assume I probably want to use refreshRecordComponent(r,c). Assuming that is correct, then what is the correct way to get the value for "r" and "c" when all I have is the value of the key field for the record and the id of the graph column (user may have reorder columns so I do not necessarily know it's current column #)? Is the column number the index of the column in the getFields() or getAllFields() list? Is the row number the index of the row in the grid's getResultSet() list?

              Comment


                #8
                Yes, getResultSet().find() variants can get you the record, and the column number is the column index. If by the "id of the graph column" you mean it's fieldName, use getFieldNum(fieldName).

                Comment


                  #9
                  Let me try to be more clear. I have the record (found by doing a find on the list grid result set), but the refresh method wants a record number (an int) not a record. I don't see any obvious way to get the record# out of the record object. How do I do this? The refresh also want the column#, is that the value returned by getFieldNum method?

                  UPDATE: (after above question was posted)
                  It seems to work if I use the resultSet.indexOf(record) and listGrid.getFieldNum(columnName) to get the row/column numbers to pass into the refresh. However, the on-screen update first blanks the cell and then draw and it seems slower than I expected to put the image in the cell after blanking it (it blanks very fast).
                  Last edited by pgrever; 7 Dec 2011, 16:31.

                  Comment


                    #10
                    ListGrid.getRecordIndex(record) would work, but you could also just call resultSet.findIndex() instead of find().

                    Comment

                    Working...
                    X