1. #1
    Ext User
    Join Date
    Aug 2009
    Location
    Italy
    Posts
    39
    Vote Rating
    0
    Estefan is on a distinguished road

      0  

    Question remove an item from the grid

    remove an item from the grid


    hi everybody.
    After a long search in the forum and after trying many methods to remove the selected item from the grid i failed.
    this grid is using the VehicleGroupInfo BaseModelData.
    how can i remove the selected item?

    List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

    CheckColumnConfig checkColumn = new CheckColumnConfig("state", " ", 55);
    CheckBox c = new CheckBox();
    CellEditor checkBoxEditor = new CellEditor(c);
    checkColumn.setEditor(checkBoxEditor);
    configs.add(checkColumn);


    ColumnConfig column = new ColumnConfig();
    column.setId("name");
    column.setHeader(myMessages.Groups());
    column.setWidth(220);

    TextField<String> text = new TextField<String>();
    text.setAllowBlank(false);
    column.setEditor(new CellEditor(text));
    configs.add(column);

    final ListStore<VehicleGroupInfo> store = new ListStore<VehicleGroupInfo>();
    store.add(TestData.getvehGroupModel());

    ColumnModel cm = new ColumnModel(configs);

    final EditorGrid<VehicleGroupInfo> grid = new EditorGrid<VehicleGroupInfo> (store, cm);
    grid.setAutoExpandColumn("name");
    grid.setBorders(true);
    grid.addPlugin(checkColumn);
    grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
    window.add(grid);






    /* window.addButton(new Button("Reset", new
    SelectionListener<ButtonEvent>() {

    @Override public void componentSelected(ButtonEvent ce) {
    store.rejectChanges(); } }));*/


    window.add(grid);

    window.addButton(new Button(myMessages.Create(),
    new SelectionListener<ButtonEvent>() {
    @Override
    public void componentSelected(ButtonEvent ce) {

    VehicleGroupInfo v = new VehicleGroupInfo();
    v.setName("type here");
    v.setState(false);

    grid.stopEditing();
    //add the new item at the end
    store.insert(v, store.getCount());
    grid.startEditing(0, 0);

    }
    }));




    // removes the selected row
    window.addButton(new Button(myMessages.Remove(),
    new SelectionListener<ButtonEvent>() {
    public void componentSelected(ButtonEvent ce)
    //code needed

    }));


    thanks in advance

  2. #2
    Ext User
    Join Date
    Sep 2008
    Location
    Germany
    Posts
    961
    Vote Rating
    1
    Arno.Nyhm is on a distinguished road

      0  

    Default


    salam!

    i have found this codesnippet in a different place, but it gives an idea how to use it - adopt it to a grid and the button event:

    PHP Code:
                remove.addSelectionListener(new SelectionListener<MenuEvent>() {

                    public 
    void componentSelected(MenuEvent ce) {
                        List<
    ModelDataselected tree.getSelectionModel().getSelectedItems();
                        for (
    ModelData sel selected) {
                            
    store.remove(sel);
                        }
                    }
                }); 

    and if you search for store.remove you find this threads:

    http://www.extjs.com/forum/showthrea...t=store.remove
    http://www.extjs.com/forum/showthrea...t=store.remove
    This forum needs your help: you got hints from the community and now you have fixed your code? dont just reply with "now its fixed" or "i found the error"! please take the time to post also an detailed answer with the working code.

    GreaseMonkey Script for a GXT-only Forum: it hides ExtJs here: New Posts • Search Results • Advanced Search form • Category overview http://www.extjs.com/forum/showthrea...041#post410041

  3. #3
    Ext User
    Join Date
    Aug 2009
    Location
    Italy
    Posts
    39
    Vote Rating
    0
    Estefan is on a distinguished road

      0  

    Default


    hi Arno
    first thanks for your reply and your links.
    i took my time to search well for the delete issue but i have the same problem all the time
    grid.getSelectionModel().getSelectedItem(); is always pointing to null.
    don't know what to do.

  4. #4
    Ext User
    Join Date
    Aug 2009
    Location
    Italy
    Posts
    39
    Vote Rating
    0
    Estefan is on a distinguished road

      0  

    Default


    salam!!!!!!! hi
    youpiiiiiiiiiiiiii.arno it is working now
    i used your second link and it is working successfully but i had to remove the CheckColumn and change the selectionModel.
    here the changes to make the code above work :


    List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

    /*checkColumn removed*/


    ColumnConfig column = new ColumnConfig();
    column.setId("name");
    column.setHeader(myMessages.Groups());
    column.setWidth(220);

    TextField<String> text = new TextField<String>();
    text.setAllowBlank(false);
    column.setEditor(new CellEditor(text));
    configs.add(column);

    final ListStore<VehicleGroupInfo> store = new ListStore<VehicleGroupInfo>();
    store.add(TestData.getvehGroupModel());

    ColumnModel cm = new ColumnModel(configs);

    final EditorGrid<VehicleGroupInfo> grid = new EditorGrid<VehicleGroupInfo>(store, cm);
    grid.setAutoExpandColumn("name");
    grid.setBorders(true);
    grid.setSelectionModel(new GridSelectionModel<VehicleGroupInfo>());

    window.add(grid);

    window.addButton(new Button(myMessages.Create(),
    new SelectionListener<ButtonEvent>() {
    @Override
    public void componentSelected(ButtonEvent ce) {

    VehicleGroupInfo v = new VehicleGroupInfo();
    v.setName(myMessages.typehere());
    v.setState(false);

    grid.stopEditing();
    //add the new item at the end
    store.insert(v, store.getCount());
    grid.startEditing(store.getCount(), 0);

    }
    }));

    // removes the selected row
    Button remove=new Button (myMessages.Remove());
    remove.addSelectionListener(new SelectionListener<ButtonEvent>() {
    public void componentSelected(ButtonEvent ce) {


    grid.stopEditing();
    currentlySelectedVehicle = grid.getSelectionModel().getSelectedItems();
    Iterator it = currentlySelectedVehicle.iterator();
    while(it.hasNext())
    {
    VehicleGroupInfo o =(VehicleGroupInfo) it.next();
    System.out.print( " Selected groups "+ o.toString());
    System.out.print(" object deleted is : "+ o.toString());
    grid.getStore().remove(o);
    }

    if (grid.getStore().getCount() == 0) {
    ce.<Component> getComponent().disable();
    }
    }



    });


    window.addButton (remove);


    hope this post will be helpful to many people.
    Thanx again arno.

  5. #5
    Ext User
    Join Date
    Sep 2008
    Location
    Germany
    Posts
    961
    Vote Rating
    1
    Arno.Nyhm is on a distinguished road

      0  

    Default


    "mabrouk aleyki"
    gratulation :-)



    PS: i like grace deeb "mabrouk aleyki"
    This forum needs your help: you got hints from the community and now you have fixed your code? dont just reply with "now its fixed" or "i found the error"! please take the time to post also an detailed answer with the working code.

    GreaseMonkey Script for a GXT-only Forum: it hides ExtJs here: New Posts • Search Results • Advanced Search form • Category overview http://www.extjs.com/forum/showthrea...041#post410041

  6. #6
    Sencha User
    Join Date
    Oct 2011
    Posts
    10
    Vote Rating
    0
    raj_s37 is an unknown quantity at this point

      0  

    Question how to implement using modelData

    how to implement using modelData


    I am using the ListStore With ModelData Object ,The class for storing the values has been implemented the ModelBeanTag.

    Please let me know how to insert / delete a data for this kind of objects.

    Its urgent please provide your input ASAP

Thread Participants: 2