1. #1
    Sencha User
    Join Date
    Jun 2013
    Posts
    7
    Vote Rating
    0
    Drim is on a distinguished road

      0  

    Default Answered: How to dynamically change text of buttons cells in Grids

    Answered: How to dynamically change text of buttons cells in Grids


    Hi,

    in my project I have a grid made for containing human ressources offers and depending on the status of the offer (an int from a enum) and from the role of the user logged in, I'd like to change the text from the ButtonCell.

    For example :
    we have 2 offers (let's call them "Offer One" and "Offer Two"),
    Offer One has a status "1" meaning "closed" and can only be consulted so I'd like to have a "Consult" text on the button
    Offer Two has a status "2" meaning "open" and can be modified so I'd like to have a "Modify" text on the button

    as long as for now, I can use UIwithHandlers to manage the dispatching after a SelectEvent but I don't know if it could be possible to add another event handler (actualy, it is possible with the addHandler method from the AbstractEventCell class but I don't know which one would fit here something like "onBind" or "onDisplay" if they exist).

    I dunno if i'm clear enough, but if anyone got an idea, I'd be more than happy to learn today ^^.

    Best regards,

    T.R

  2. The point of a cell is to have a single object that renders all of the instances of that column's value. In the Grid, each cell gets its data from the ValueProvider in that ColumnConfig, and renders as it likes.

    The TextButtonCell/ButtonCell treats its incoming value as a String (unless it is a boolean as in toggle button), and renders that (based on the ValueProvider, etc). If you have drawn these items in the grid, and the data itself is in the store, you can modify the model object and call store.update(model) to get the grid to redraw the row with the new values.

    I hope this helps - to be much more specific about your use case, we would need to see some specifics of how that cell and grid are being used.

  3. #2
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,732
    Answers
    109
    Vote Rating
    90
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      1  

    Default


    The point of a cell is to have a single object that renders all of the instances of that column's value. In the Grid, each cell gets its data from the ValueProvider in that ColumnConfig, and renders as it likes.

    The TextButtonCell/ButtonCell treats its incoming value as a String (unless it is a boolean as in toggle button), and renders that (based on the ValueProvider, etc). If you have drawn these items in the grid, and the data itself is in the store, you can modify the model object and call store.update(model) to get the grid to redraw the row with the new values.

    I hope this helps - to be much more specific about your use case, we would need to see some specifics of how that cell and grid are being used.

  4. #3
    Sencha User
    Join Date
    Jun 2013
    Posts
    7
    Vote Rating
    0
    Drim is on a distinguished road

      0  

    Default


    Hi,

    I answer a bit late, but thanks for your concern (and time).
    I almost forgot that it's still possible to make a custom valueprovider, i'll show here what i used to do what I wanted

    Code:
    ValueProvider<CandidatureDTO, String> consultModifLabelProvider = new ValueProvider<CandidatureDTO, String>() {
    
    
                @Override
                public String getValue(CandidatureDTO candidature) {
                    return candidature.isModifiable() ? selectMessages.lblHomeTabBtnModify() : selectMessages.lblHomeTabBtnConsult();
                }
    
    
                @Override
                public void setValue(CandidatureDTO candidature, String value) {
    
    
                }
    
    
                @Override
                public String getPath() {
                    return null;
                }
            };
    ColumnConfig<CandidatureDTO, String> modifConsultCandidature = new ColumnConfig<CandidatureDTO, String>(consultModifLabelProvider, 150, selectMessages.lblHomeTabConsultModify());
    
    TextButtonCell buttonCell = new TextButtonCell();
    buttonCell.addSelectHandler(new SelectHandler() {
    
    
                @Override
                public void onSelect(SelectEvent event) {
                    Context c = event.getContext();
                    int row = c.getIndex();
                    CandidatureDTO p = store.get(row);
                    if (getUiHandlers() != null) {
                        getUiHandlers().onConsultModifyApplicationButtonSelect(p);
                    }
                }
            });
    modifConsultCandidature.setCell(buttonCell);
    That was pretty simple in the end and works well but I hadn't thought about it at first .
    PS : (yes, if you notice the getUiHandlers() you know i'm using GWTP )

Thread Participants: 1

Tags for this Thread