Gelmiş geçmiş en büyük porno sitemiz olan 2pe de her zaman en kaliteli pornoları sunmayı hedefledik. Diğer video sitemiz olan vuam da ise hd porno ağırlıklı çalışmalara başladık.

  1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    25
    Vote Rating
    0
    Steve_Terry is on a distinguished road

      0  

    Default Answered: ActionColumn - Item Tooltip = Item Icon URL?

    Answered: ActionColumn - Item Tooltip = Item Icon URL?


    Hi there,

    So I have a grid which consists of an actioncolumn and what's being displayed in that actioncolumn for each row is an item which consists of a defined tooltip and icon.

    For instance, the actioncolumn is essentially defined as such...

    Code:
    xtype: 'actioncolumn',
    id: 'TestActiveCol',
    dataIndex: 'Active',
    text: 'Active',
    items: 
    [{
         icon   : 'enable_icon_url_path',
         tooltip: 'Enable'
    }]
    My goal is to, let's say, click a button and once clicked, toggle the icon and tooltip of that item to be either "enabled" or "disabled".

    So essentially, by default the actioncolumn cells for all rows of the grid will contain an item which consists of an "Enabled" say checkmark icon and an "Enable" tooltip if the user hovers over the icon.

    When the user clicks the "ChangeItem" button it will change the items icon to be "Disabled" say red x icon and a "Disabled" tooltip will display if the user hovers over the icon.

    My code for this "ChangeItem" method implementation is as such...

    Code:
    //variable for action column
    var activeColumn = Ext.getCmp('TestActiveCol'); 
    
    //If a row of the grid is selected (aka an index 0 or above) than proceed
    if(grid.store.indexOf(grid.getSelectionModel().getSelection()[0]) != -1) 
    {   
                //variable for the selected row
                var selectedRow = store.getAt(grid.store.indexOf(grid.getSelectionModel().getSelection()[0]));
                
                //variable for the selected row's item tooltip value
                var tooltipValue = selectedRow.get('Active', activeColumn.items[0].tooltip);
    
                //Log to console the value which is stored in the tooltip
                console.log(tooltipValue);
    
                //If the tooltip's value does not equal Disable than proceed
                if(tooltipValue != 'Disable')
               {
                    //Set the selected row's item tooltip to Disable
                    selectedRow.set('Active', activeColumn.items[0].tooltip = 'Disable');
                    //Set the selected row's item icon to the Disable icon
                    selectedRow.set('Active', activeColumn.items[0].icon = 'disable_icon_url_path');
                }
    }
    and the code above is vice versa for Enable as well.

    Problem: What I am receiving from the following lines of code...

    Code:
    //variable for the selected row's item tooltip value
    var tooltipValue = selectedRow.get('Active', activeColumn.items[0].tooltip);
    
    //Log to console the value which is stored in the tooltip
    console.log(tooltipValue);
    is that the firebug console is displaying the item's icon url path and not the item's tooltip value.

    So when the following above is first ran, since enable tooltip/icon is set by default, I am receiving the following in the console...

    Code:
    enable_icon_url_path
    however, my expected result is to receive the tooltip's value in the console such as the following...

    Code:
    Enable
    I could make the following change to the code...

    Code:
    if(tooltipValue != 'disable_icon_url_path')
    but that definitely looks incorrect to me as a workaround.

    I thought this might be a bug but most likely I am doing 1 small error which is causing the problem.

    Any ideas from the support staff?

    Any help is greatly appreciated!

    Thanks!

  2. @Steve_Terry,

    Basing on your modified code, I have some suggestions as below:
    Code:
    //variable for action column
    // var activeColumn = Ext.getCmp('TestActiveCol'); <- This line of code is no need
    
    //variable for the selected row
    var selectedRow = grid.getSelectionModel().getSelection()[0]; 
    
    
    if(selectedRow) {
        //var selectedRowIndex = store.getAt(grid.store.indexOf(selectedRow)); <- this line of code is no need because selectedRowIndex is exactly the same as selectedRow. 
    
        //var selectedRowActiveValue = selectedRowIndex.get('Active');  <- use selectedRow instead
        var selectedRowActiveValue = selectedRow.get('Active');
    
        if(selectedRowActiveValue != 0){
            selectedRowIndex.set('Active', 0);
        } else {
            selectedRowIndex.set('Active', 1);
        }
    }
    ActionColumn config
    xtype: 'actioncolumn',
    id: 'TestActiveCol',
    dataIndex: 'Active',
    text: 'Active',
    items: [{
    getClass: function(v, meta, rec){
    if(rec.get('Active') == '0'){
    this.items[0].icon = 'enable_icon_url_path';
    this.items[0].tooltip = 'Enable';
    } else {
    this.items[0].icon = 'disable_icon_url_path';
    this.items[0].tooltip = 'Disable';
    }
    }
    }]
    If you want to apply icon and tooltip for the current row, you should change them in renderer() instead of getClass() because getClass() is called a little late when item.icon has been used. The result will not be exact. I guess, if you change icon and tooltip this way, the icon will be applied for the next row, tooltip will be applied for the current row. So I suggest you to modify actioncolumn config as follow:
    Code:
    xtype: 'actioncolumn',
    id: 'TestActiveCol',
    dataIndex: 'Active',
    text: 'Active',
    renderer: function(value, meta, rec){
        var items = this.down('actioncolumn[id=TestActiveCol]').items;
        if(rec.get('Active') == '0'){  // you can use value instead of rec.get('Active') eg if(value == 0) {
            items[0].icon = 'enable_icon_url_path';
            items[0].tooltip = 'Enable';
        } else {     
            items[0].icon = 'disable_icon_url_path';
            items[0].tooltip = 'Disable';
        }
    },
    items: [{
    }]

  3. #2
    Sencha - Community Support Team
    Join Date
    Jan 2012
    Posts
    1,376
    Answers
    346
    Vote Rating
    113
    vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all

      0  

    Default


    //variable for the selected row's item tooltip value
    var tooltipValue = selectedRow.get('Active', activeColumn.items[0].tooltip);

    //Log to console the value which is stored in the tooltip
    console.log(tooltipValue);
    selectedRow.get('Active', activeColumn.items[0].tooltip) returns the value of field 'Active' in the selectedRow. The argument activeColumn.items[0].tooltip is not used. You can check the syntax of get()method here Ext.data.Model-method-get.

    ...
    if(grid.store.indexOf(grid.getSelectionModel().getSelection()[0]) != -1) {
    //variable for the selected row
    var selectedRow = store.getAt(grid.store.indexOf(grid.getSelectionModel().getSelection()[0]));
    ...
    It's complicated and no need. You can simplify this code as follow:
    Code:
    var selectedRecord = grid.getSelectionModel().getSelection()[0]; // or selectedRecord = grid.getSelectionModel().getLastSelected();
    if(selectedRecord){
        ....
    }
    if(tooltipValue != 'Disable'){
    //Set the selected row's item tooltip to Disable
    selectedRow.set('Active', activeColumn.items[0].tooltip = 'Disable');
    //Set the selected row's item icon to the Disable icon
    selectedRow.set('Active', activeColumn.items[0].icon = 'disable_icon_url_path');
    }
    See Ext.data.Model-method-set for set() method syntax.

    There are many problems with your code! You could refer to the example of array-grid in examples/grid/ folder. It has an actioncolumn that allows switching the icon, tooltip basing on the value of a field in current record.

  4. #3
    Sencha User
    Join Date
    Feb 2012
    Posts
    25
    Vote Rating
    0
    Steve_Terry is on a distinguished road

      0  

    Default


    Hi Vietits,

    Thanks for your response.

    Although I'm very confused when you mentioned there are many problems with the code?

    The code works alright (not great) in what it should be doing minus a few small changes but for me starting out, I really don't see the many problems you mentioned below.

    I do understand that "Yes" I am supplying an additional (unnecessary) argument to the .get method (which I will remove so thanks ) although it still puzzles me (since I'm new sorry) that if the .get method returns the value of the given field than why am I only receiving the item icon url value instead of the item tooltip value as well?

    I would expect that if the value of the field contained the item than both of the item's properties would be accessible not just the icon url.

    Also the reason why I added the following code...

    Code:
    if(grid.store.indexOf(grid.getSelectionModel().getSelection()[0]) != -1)
    is for any possible cases in which the index could quite possibly go out of bounds because as far as I understand, an index location not found will return a -1.

    I also don't really see what's wrong with the .set method as well.

    According to the doc it sets the given field to the given value so in the case below...

    Code:
    selectedRow.set('Active', activeColumn.items[0].tooltip = 'Disable');
    I am assuming that I'm setting the 'Active' field's item tooltip value to 'Disable'.

    If you're saying that's incorrect than I'm very confused because when the .set methods in my code execute, it works perfectly by not only changing the icon image (based on my url specified) but also changing the tooltip as well.

  5. #4
    Sencha - Community Support Team
    Join Date
    Jan 2012
    Posts
    1,376
    Answers
    346
    Vote Rating
    113
    vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all

      0  

    Default


    @Steve_Sterry,

    OK, let me talk more details about what I mentioned:
    if(grid.store.indexOf(grid.getSelectionModel().getSelection()[0]) != -1) {
    //variable for the selected row
    var selectedRow = store.getAt(grid.store.indexOf(grid.getSelectionModel().getSelection()[0]));
    I understood what you mean with this code. I did not say that your code is wrong, but it is complicated and not need to do so. I will say why by analyzing your code step by step:

    1. grid.store.indexOf(grid.getSelectionModel().getSelection()[0]) != -1: This code get the first row from selected rows on the grid and then check to see whether or not it is in the store. If it returns true then you go inside the if block (step 2). This is OK.

    2. When you are inside the if block it means that grid.getSelectionModel().getSelection()[0] is the selected row that you want. Then the code var selectedRow = store.getAt(grid.store.indexOf(grid.getSelectionModel().getSelection()[0]))
    is no need except it assigns the selected row to variable selectedRow. Let check two lines of code below and you will see they are the same:
    • console.log(grid.getSelectionModel().getSelection()[0]);
    • console.log(store.getAt(grid.store.indexOf(grid.getSelectionModel().getSelection()[0])));
    Basing on what I analyzed above, I suggested to modify your code as what I mentioned:
    Code:
    // var selectedRow = grid.getSelectionModel().getLastSelected();
    var selectedRow = grid.getSelectionModel().getSelection()[0]; 
    if(selectedRow){ // if there is at least one selected row then go inside
        ....
    }
    //variable for the selected row's item tooltip value
    var tooltipValue = selectedRow.get('Active', activeColumn.items[0].tooltip);
    As I said, this line of code will get value of the 'Active' field from the selectedRow not from activeColumn.items[0].tooltip. It also anwers for the question you raised in the first post. You expect to receive the tooltip value but instead it turns out to be 'enable_icon_url_path'.

    Since tooltipValue will have the value of the 'Active' field of the selectedRow, so I guess 'Active' field initially has value of 'enable_icon_url_path'.

    I am sure, next time this code is executed (with the same selected row), tooltipValue will have the value of 'disable_icon_url_path'. Next part will reveal why.

    //If the tooltip's value does not equal Disable than proceed
    if(tooltipValue != 'Disable')
    {
    //Set the selected row's item tooltip to Disable
    selectedRow.set('Active', activeColumn.items[0].tooltip = 'Disable');
    //Set the selected row's item icon to the Disable icon
    selectedRow.set('Active', activeColumn.items[0].icon = 'disable_icon_url_path');
    }
    Surely, this block of code is always executed because tooltipValue is always different 'Disable'.

    Your code can be re-written as below:
    Code:
    //If the tooltip's value does not equal Disable than proceed
    if(tooltipValue != 'Disable')
    {
        //Set the selected row's item tooltip to Disable
        activeColumn.items[0].tooltip = 'Disable';   // line 1
        selectedRow.set('Active', activeColumn.items[0].tooltip);   // line 2
    
    
        //Set the selected row's item icon to the Disable icon
        activeColumn.items[0].icon = 'disable_icon_url_path';   // line 3
        selectedRow.set('Active', activeColumn.items[0].icon);  // line 4
    }
    Line 1: Assigns 'Disable' to activeColumn.items[0].tooltip
    Line 2: Set 'Active' field with the value of activeColumn.items[0].tooltip. After this line, 'Active' field will contain 'Disable'.
    Line 3: Assigns 'disable_icon_url_path' to activeColumn.items[0].icon.
    Line 4: Set 'Active' field with the value of activeColumn.items[0].icon. This will override the result of the Line 2 and after this line 'Active' field will contain 'disable_icon_url_path'. This is the reason why I said above that from the second time tooltipValue will have the value of 'disable_icon_url_path'.

    xtype: 'actioncolumn',
    id: 'TestActiveCol',
    dataIndex: 'Active',
    text: 'Active',
    items:
    [{
    icon : 'enable_icon_url_path',
    tooltip: 'Enable'
    }]
    I saw that you configured the actioncolumn to link it with 'Active' field, but you did not define a method to process your column basing on the value of this field (in this case is getClass). Default implementation of actioncolumn does not use dataIndex. That the reason why I suggested you to refer to the array-grid example (in folder examples/grid).

  6. #5
    Sencha User
    Join Date
    Feb 2012
    Posts
    25
    Vote Rating
    0
    Steve_Terry is on a distinguished road

      0  

    Default


    @vietits,

    Thanks for the update, I understand what you wrote in your modified code version of selecting a grid row...so essentially the variable (of the selected row) is being defined before the if_statement which not only allows the variable to be used in the check but of course also inside the if_statement so duplicate cases (or additional references to the selected row) don't need to exist.

    Please correct me if I'm wrong but (according to your suggestions/example you mentioned) I have made the following changes which appear to be working...

    ActionColumn Code
    Code:
    xtype: 'actioncolumn',
    id: 'TestActiveCol',
    dataIndex: 'Active',
    text: 'Active',
    items: [{
            getClass: function(v, meta, rec)
            {    
                if(rec.get('Active') == '0')
                {
                    this.items[0].icon = 'enable_icon_url_path';
                    this.items[0].tooltip = 'Enable';
                }
                else
                {     
                    this.items[0].icon = 'disable_icon_url_path';
                    this.items[0].tooltip = 'Disable';
                }
            }
            }]
    ChangeItem Method Code
    Code:
    //variable for action column
    var activeColumn = Ext.getCmp('TestActiveCol');
    
    //variable for the selected row
    var selectedRow = grid.getSelectionModel().getSelection()[0]; 
    
    if(selectedRow) 
    {      
        var selectedRowIndex = store.getAt(grid.store.indexOf(selectedRow));
    
        var selectedRowActiveValue = selectedRowIndex.get('Active');
    
        if(selectedRowActiveValue != 0)
        {
             selectedRowIndex.set('Active', 0);
         }
         else
             selectedRowIndex.set('Active', 1);
    }
    So essentially if my understand is correct, I should actually be setting the 'Active' field of the selected row and due to the change (you suggested) in the ActionColumn, anytime this 'Active' field changes value, the getClass is called and will check whether the 'Active' value is set to a 0 or 1 ultimately changing the selected row's item.tooltip and item.icon.

    It appears to be working correct on my end.

    I'm pretty sure my understanding of getClass is still not accurate but let me know what you think or perhaps any improvements, maybe I still am doing it incorrectly.

  7. #6
    Sencha - Community Support Team
    Join Date
    Jan 2012
    Posts
    1,376
    Answers
    346
    Vote Rating
    113
    vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all

      0  

    Default


    @Steve_Terry,

    Basing on your modified code, I have some suggestions as below:
    Code:
    //variable for action column
    // var activeColumn = Ext.getCmp('TestActiveCol'); <- This line of code is no need
    
    //variable for the selected row
    var selectedRow = grid.getSelectionModel().getSelection()[0]; 
    
    
    if(selectedRow) {
        //var selectedRowIndex = store.getAt(grid.store.indexOf(selectedRow)); <- this line of code is no need because selectedRowIndex is exactly the same as selectedRow. 
    
        //var selectedRowActiveValue = selectedRowIndex.get('Active');  <- use selectedRow instead
        var selectedRowActiveValue = selectedRow.get('Active');
    
        if(selectedRowActiveValue != 0){
            selectedRowIndex.set('Active', 0);
        } else {
            selectedRowIndex.set('Active', 1);
        }
    }
    ActionColumn config
    xtype: 'actioncolumn',
    id: 'TestActiveCol',
    dataIndex: 'Active',
    text: 'Active',
    items: [{
    getClass: function(v, meta, rec){
    if(rec.get('Active') == '0'){
    this.items[0].icon = 'enable_icon_url_path';
    this.items[0].tooltip = 'Enable';
    } else {
    this.items[0].icon = 'disable_icon_url_path';
    this.items[0].tooltip = 'Disable';
    }
    }
    }]
    If you want to apply icon and tooltip for the current row, you should change them in renderer() instead of getClass() because getClass() is called a little late when item.icon has been used. The result will not be exact. I guess, if you change icon and tooltip this way, the icon will be applied for the next row, tooltip will be applied for the current row. So I suggest you to modify actioncolumn config as follow:
    Code:
    xtype: 'actioncolumn',
    id: 'TestActiveCol',
    dataIndex: 'Active',
    text: 'Active',
    renderer: function(value, meta, rec){
        var items = this.down('actioncolumn[id=TestActiveCol]').items;
        if(rec.get('Active') == '0'){  // you can use value instead of rec.get('Active') eg if(value == 0) {
            items[0].icon = 'enable_icon_url_path';
            items[0].tooltip = 'Enable';
        } else {     
            items[0].icon = 'disable_icon_url_path';
            items[0].tooltip = 'Disable';
        }
    },
    items: [{
    }]
    Last edited by vietits; 1 Mar 2012 at 4:17 PM. Reason: correct the code

  8. #7
    Sencha User
    Join Date
    Mar 2010
    Posts
    12
    Vote Rating
    0
    lironla is on a distinguished road

      0  

    Default where do i put the changeitem method ???

    where do i put the changeitem method ???


    when pressing on an icon in the column (toggle) (id = 'TestActiveCol') , I don't see any changes....

    this is my code :


    Ext.Loader.setConfig({
    enabled: true
    });
    Ext.Loader.setPath('Ext.ux', '../ux');


    Ext.require([
    'Ext.grid.*',
    'Ext.data.*',
    'Ext.util.*',
    'Ext.state.*',
    'Ext.form.*',
    'Ext.ux.CheckColumn',
    'Ext.ux.dd.GridReorderDropTarget'
    ]);


    Ext.onReady(function(){
    // Define our data model
    Ext.define('Rule', {
    extend: 'Ext.data.Model',
    fields: [
    {name: 'number', type: 'float'},
    {name: 'track'},
    {name: 'comment', type: 'string'},

    { name: 'active', type: 'bool' },
    { name: 'enable', type: 'bool' }
    ]
    });


    // Generate mock rule data
    var data = (function() {
    var comments = ['Hit', 'The', 'Road', 'Jack', 'And', 'Dont', 'You', 'Come', 'Back', 'No', 'More'],

    commentslen = comments.length,

    data = [],
    start = 0,
    end = 20,


    getRandomInt = function(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
    },


    generateComment = function() {
    var name = comments[getRandomInt(0, commentslen - 1)];

    return name;
    };


    while (start < end) {
    var name = generateComment();
    data.push({
    numbertart+1,
    track : 'Alert',
    comment: name.toLowerCase().replace(' ', '.'),

    active: getRandomInt(0, 1) ,
    enable:0
    });

    start = start+1;
    }


    return data;
    })();


    // create the Data Store
    var store = Ext.create('Ext.data.Store', {
    // destroy the store if the grid is destroyed
    autoDestroy: true,
    model: 'Rule',
    proxy: {
    type: 'memory'
    },
    data: data,
    sorters: [{
    property: 'number',
    direction: 'ASC'
    }]
    });


    var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
    clicksToMoveEditor: 1,
    autoCancel: false
    });


    // create the grid and specify what field you want
    // to use for the editor at each column.
    var grid = Ext.create('Ext.grid.Panel', {
    xtype:"grid",
    store: store,
    columns: [
    new Ext.grid.RowNumberer(),
    {
    header: 'Rule Number',
    dataIndex: 'number',
    width: 70,
    align: 'right',
    editor: {
    xtype: 'numberfield',
    allowBlank: false,
    minValue: 1,
    maxValue: 100000
    }
    },
    {
    header: 'Track',
    dataIndex: 'track',
    width: 130,
    editor: {
    xtype: 'combobox',
    typeAhead: true,
    triggerAction: 'all',
    selectOnTab: true,
    store: [
    ['Alert','Alert'],
    ['None','None'],
    ['Log','Log']
    ],
    lazyRender: true,
    listClass: 'x-combo-list-small'
    }
    },
    {
    header: 'Comment',
    dataIndex: 'comment',
    flex: 1,
    editor: {
    // defaults to textfield if no xtype is supplied
    allowBlank: false
    }
    },
    {
    xtype: 'checkcolumn',
    header: 'Active?',
    dataIndex: 'active',
    width: 60,
    editor: {
    xtype: 'checkbox',
    cls: 'x-grid-checkheader-editor'
    }


    },
    {
    xtype: 'actioncolumn',
    id: 'TestActiveCol',
    dataIndex: 'Enable',
    text: 'Enable',
    renderer: function(value, meta, rec){
    var items = this.down('actioncolumn[id=TestActiveCol]').items;
    if(rec.get('Enable') == '0'){ // you can use value instead of rec.get('Active') eg if(value == 0) {
    items[0].icon = '../shared/icons/fam/remove.gif';
    items[0].tooltip = 'Enable';
    } else {
    items[0].icon = '../shared/icons/fam/add.gif';
    items[0].tooltip = 'Disable';
    }
    },
    items: [{
    }]
    },
    {
    xtype: 'actioncolumn',
    header: 'Remove Rule',
    items: [
    {
    xtype: 'button',
    icon: '../shared/icons/fam/delete.gif',
    tooltip: 'Delete',
    handler: function(grid, rowIndex, colIndex)
    {
    var rec = grid.getStore().getAt(rowIndex);
    rowEditing.cancelEdit();
    store.remove(rec);
    if (store.getCount() > 0) {
    sm.select(0);
    }
    }
    }
    ]
    }],
    renderTo: 'editor-grid',
    width: 600,
    height: 400,
    title: 'Security Rule Bar',
    frame: true,
    tbar: [{
    text: 'Add Rule',
    icon: '../shared/icons/fam/add.gif',
    handler : function() {
    rowEditing.cancelEdit();


    // Create a model instance
    var r = Ext.create('Rule', {
    number: 1,
    track: 'Alert',
    comment: 'New One',
    active: true
    });


    store.insert(0, r);
    rowEditing.startEdit(0, 0);
    }
    }, {
    itemId: 'removeRule',
    text: 'Remove Rule',
    icon: '../shared/icons/fam/cross.gif',
    handler: function() {
    var sm = grid.getSelectionModel();
    rowEditing.cancelEdit();
    store.remove(sm.getSelection());
    if (store.getCount() > 0) {
    sm.select(0);
    }
    },
    disabled: true
    }],
    plugins: [rowEditing],
    listeners: {
    'selectionchange': function(view, records) {
    grid.down('#removeRule').setDisabled(!records.length);
    }
    }
    });
    });

  9. #8
    Sencha User
    Join Date
    Mar 2010
    Posts
    12
    Vote Rating
    0
    lironla is on a distinguished road

      0  

    Default this is more like it....

    this is more like it....


    Code:
    /*
    
    
    This file is part of Ext JS 4
    
    
    Copyright (c) 2011 Sencha Inc
    
    
    Contact:  http://www.sencha.com/contact
    
    
    Commercial Usage
    Licensees holding valid commercial licenses may use this file in accordance with the Commercial Software License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and Sencha.
    
    
    If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
    
    
    */
    Ext.Loader.setConfig({
        enabled: true
    });
    Ext.Loader.setPath('Ext.ux', '../ux');
    
    
    Ext.require([
        'Ext.grid.*',
        'Ext.data.*',
        'Ext.util.*',
        'Ext.state.*',
        'Ext.form.*',
        'Ext.ux.CheckColumn',
        'Ext.ux.dd.GridReorderDropTarget'
    ]);
    
    
    Ext.onReady(function(){
        // Define our data model
        Ext.define('Rule', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'number', type: 'float'},
                {name: 'track'},
                 {name: 'comment', type: 'string'},
                
                { name: 'active', type: 'bool' },
                 { name: 'enable', type: 'bool' }
            ]
        });
    
    
        // Generate mock rule data
        var data = (function() {
            var comments = ['Hit', 'The', 'Road', 'Jack', 'And', 'Dont', 'You', 'Come', 'Back', 'No', 'More'],
                
                commentslen = comments.length,
                
                data = [],
                start = 0,
                end = 20,
    
    
                getRandomInt = function(min, max) {
                    return Math.floor(Math.random() * (max - min + 1)) + min;
                },
    
    
                generateComment = function() {
                    var name = comments[getRandomInt(0, commentslen - 1)];
                    
                    return name;
                };
    
    
            while (start < end) {           
                    var name = generateComment();
                    data.push({
                        number:start+1,
                        track : 'Alert',
                        comment: name.toLowerCase().replace(' ', '.'),
                        
                        active: getRandomInt(0, 1)  ,
                        enable:0                 
                    });
                
                start = start+1;
            }
    
    
            return data;
        })();
    
    
        // create the Data Store
        var store = Ext.create('Ext.data.Store', {
            // destroy the store if the grid is destroyed
            autoDestroy: true,
            model: 'Rule',
            proxy: {
                type: 'memory'
            },
            data: data,
            sorters: [{
                property: 'number',
                direction: 'ASC'
            }]
        });
    
    
        var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
            clicksToMoveEditor: 1,
            autoCancel: false
        });
    
    
        // create the grid and specify what field you want
        // to use for the editor at each column.
        var grid = Ext.create('Ext.grid.Panel', {
            xtype:"grid",
            store: store,
            columns: [ 
            new Ext.grid.RowNumberer(),
            {
                header: 'Rule Number',
                dataIndex: 'number',
                width: 70,
                align: 'right',            
                editor: {
                    xtype: 'numberfield',
                    allowBlank: false,
                    minValue: 1,                
                    maxValue: 100000
                }
            },  
            {
                header: 'Track',
                dataIndex: 'track',
                width: 130,
                editor: {
                    xtype: 'combobox',
                    typeAhead: true,
                    triggerAction: 'all',
                    selectOnTab: true,
                    store: [
                        ['Alert','Alert'],
                        ['None','None'],
                        ['Log','Log']
                    ],
                    lazyRender: true,
                    listClass: 'x-combo-list-small'
                }
            }, 
            {
                header: 'Comment',
                dataIndex: 'comment',
                flex: 1,
                editor: {
                    // defaults to textfield if no xtype is supplied
                    allowBlank: false
                }        
            }, 
            {
                xtype: 'checkcolumn',
                header: 'Active?',
                dataIndex: 'active',
                width: 60,
                editor: {
                    xtype: 'checkbox',
                    cls: 'x-grid-checkheader-editor'
                }
    
    
            },
           {
                xtype: 'actioncolumn',
                id: 'TestActiveCol',
                dataIndex: 'Enable',
                text: 'Enable',
                renderer: function(value, meta, rec){
                    var items = this.down('actioncolumn[id=TestActiveCol]').items;
                    if(rec.get('Enable') == '0'){  // you can use value instead of rec.get('Active') eg if(value == 0) {
                        items[0].icon = '../shared/icons/fam/remove.gif';
                        items[0].tooltip = 'Enable';
                    } else {     
                        items[0].icon = '../shared/icons/fam/add.gif';
                        items[0].tooltip = 'Disable';
                    }
                },
                items: [{
                }]
            }, 
            {
                xtype: 'actioncolumn', 
                header: 'Remove Rule',
                items: [
                {
                    xtype: 'button',
                    icon: '../shared/icons/fam/delete.gif',
                    tooltip: 'Delete',
                    handler: function(grid, rowIndex, colIndex)
                    {
                        var rec = grid.getStore().getAt(rowIndex);
                        rowEditing.cancelEdit();
                        store.remove(rec);
                        if (store.getCount() > 0) {
                            sm.select(0);
                        }
                    }
                }
                ]
            }],
            renderTo: 'editor-grid',
            width: 600,
            height: 400,
            title: 'Security Rule Bar',
            frame: true,
            tbar: [{
                text: 'Add Rule',
                icon: '../shared/icons/fam/add.gif',
                handler : function() {
                    rowEditing.cancelEdit();
    
    
                    // Create a model instance
                    var r = Ext.create('Rule', {
                        number: 1,
                        track: 'Alert',
                        comment: 'New One',                   
                        active: true
                    });
    
    
                    store.insert(0, r);
                    rowEditing.startEdit(0, 0);
                }
            }, {
                itemId: 'removeRule',
                text: 'Remove Rule',
                icon: '../shared/icons/fam/cross.gif',
                handler: function() {
                    var sm = grid.getSelectionModel();
                    rowEditing.cancelEdit();
                    store.remove(sm.getSelection());
                    if (store.getCount() > 0) {
                        sm.select(0);
                    }
                },
                disabled: true
            }],
            plugins: [rowEditing],     
            listeners: {
                'selectionchange': function(view, records) {
                    grid.down('#removeRule').setDisabled(!records.length);
                }
            }
        });
    });

  10. #9
    Sencha User
    Join Date
    Mar 2010
    Posts
    12
    Vote Rating
    0
    lironla is on a distinguished road

      0  

    Default what should I add that 'enabled' column will be toggled ?

    what should I add that 'enabled' column will be toggled ?


    when I click on a gif it will be toggled to another one.

    I did the actioncolumn.

    should I add and event ? and where ?

    Code:
    
    Ext.Loader.setConfig({
        enabled: true
    });
    Ext.Loader.setPath('Ext.ux', '../ux');
    
    
    Ext.require([
        'Ext.grid.*',
        'Ext.data.*',
        'Ext.util.*',
        'Ext.state.*',
        'Ext.form.*',
        'Ext.ux.CheckColumn'
    ]);
    
    
    
    
    
    
    Ext.onReady(function(){
        // Define our data model
        Ext.define('Rule', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'number', type: 'float'},
                {name: 'track'},
                 {name: 'comment', type: 'string'},
                
                { name: 'active', type: 'bool' },
                 { name: 'enable', type: 'string' }
            ]
        });
    
    
    
    
        
        // Generate mock rule data
        var data = (function() {
            var comments = ['Hit', 'The', 'Road', 'Jack', 'And', 'Dont', 'You', 'Come', 'Back', 'No', 'More'],
                
                commentslen = comments.length,
                
                data = [],
                start = 0,
                end = 20,
    
    
                getRandomInt = function(min, max) {
                    return Math.floor(Math.random() * (max - min + 1)) + min;
                },
    
    
                generateComment = function() {
                    var name = comments[getRandomInt(0, commentslen - 1)];
                    
                    return name;
                };
    
    
            while (start < end) {           
                    var name = generateComment();
                    data.push({
                        number:start+1,
                        track : 'Alert',
                        comment: name.toLowerCase().replace(' ', '.'),
                        
                        active: getRandomInt(0, 1)  ,
                        enable:0                 
                    });
                
                start = start+1;
            }
    
    
            return data;
        })();
    
    
        // create the Data Store
        var store = Ext.create('Ext.data.Store', {
            // destroy the store if the grid is destroyed
            autoDestroy: true,
            model: 'Rule',
            proxy: {
                type: 'memory'
            },
            data: data,
            sorters: [{
                property: 'number',
                direction: 'ASC'
            }]
        });
    
    
        var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
            clicksToMoveEditor: 1,
            autoCancel: false
        });
    
    
        // create the grid and specify what field you want
        // to use for the editor at each column.
        var grid = Ext.create('Ext.grid.Panel', {
            xtype:"grid",
            store: store,
            viewConfig: {
                  plugins: {
                    ptype: 'gridviewdragdrop',
                    dragGroup: 'gridDDGroup',
                    dropGroup: 'gridDDGroup'
                  }
            },
            columns: [ 
            new Ext.grid.RowNumberer(),
            {
                header: 'Rule Number',
                dataIndex: 'number',
                width: 70,
                align: 'right',            
                editor: {
                    xtype: 'numberfield',
                    allowBlank: false,
                    minValue: 1,                
                    maxValue: 100000
                }
            },  
            {
                header: 'Track',
                dataIndex: 'track',
                width: 130,
                editor: {
                    xtype: 'combobox',
                    typeAhead: true,
                    triggerAction: 'all',
                    selectOnTab: true,
                    store: [
                        ['Alert','Alert'],
                        ['None','None'],
                        ['Log','Log']
                    ],
                    lazyRender: true,
                    listClass: 'x-combo-list-small'
                }
            }, 
            {
                header: 'Comment',
                dataIndex: 'comment',
                flex: 1,
                editor: {
                    // defaults to textfield if no xtype is supplied
                    allowBlank: false
                }        
            }, 
            {
                xtype: 'checkcolumn',
                header: 'Active?',
                dataIndex: 'active',
                width: 60,
                editor: {
                    xtype: 'checkbox',
                    cls: 'x-grid-checkheader-editor'
                }
    
    
            },
            {
                xtype: 'actioncolumn',
                header: 'Enabled',
                id: 'TestActiveCol',
                dataIndex: 'enable',
                text: 'Enable',
                renderer: function(value, meta, rec){
                    var items = this.down('actioncolumn[id=TestActiveCol]').items;
                    if(rec.get('enable') == '0'){  // you can use value instead of rec.get('Active') eg if(value == 0) {
                       
                        items[0].icon = '../shared/icons/fam/add.gif';
                        items[0].tooltip = 'Enable';
                    } else {     
    
    
                        items[0].icon = '../shared/icons/fam/delete.gif';
                        items[0].tooltip = 'Disable';
                    }
                },
                items: [{
                }]
    
    
            },
          
            {
                xtype: 'actioncolumn', 
                header: 'Remove Rule',
                items: [
                {
                    xtype: 'button',
                    icon: '../shared/icons/fam/delete.gif',
                    tooltip: 'Delete',
                    handler: function(grid, rowIndex, colIndex)
                    {
                        var rec = grid.getStore().getAt(rowIndex);
                        rowEditing.cancelEdit();
                        store.remove(rec);
                        if (store.getCount() > 0) {
                            sm.select(0);
                        }
                    }
                }
                ]
            }],
            renderTo: 'editor-grid',
            width: 600,
            height: 400,
            title: 'Security Rule Bar',
            frame: true,
            tbar: [{
                text: 'Add Rule',
                icon: '../shared/icons/fam/add.gif',
                handler : function() {
                    rowEditing.cancelEdit();
    
    
                    // Create a model instance
                    var r = Ext.create('Rule', {
                        number: 1,
                        track: 'Alert',
                        comment: 'New One',                   
                        active: true
                    });
    
    
                    store.insert(0, r);
                    rowEditing.startEdit(0, 0);
                }
            }, {
                itemId: 'removeRule',
                text: 'Remove Rule',
                icon: '../shared/icons/fam/cross.gif',
                handler: function() {
                    var sm = grid.getSelectionModel();
                    rowEditing.cancelEdit();
                    store.remove(sm.getSelection());
                    if (store.getCount() > 0) {
                        sm.select(0);
                    }
                },
                disabled: true
            }],
            plugins: [rowEditing],     
            listeners: {
                'selectionchange': function(view, records) {
                    grid.down('#removeRule').setDisabled(!records.length);
    
    
                   
                }
            }
    
    
    
    
               
        });
    
    
     
    });

  11. #10
    Sencha - Community Support Team
    Join Date
    Jan 2012
    Posts
    1,376
    Answers
    346
    Vote Rating
    113
    vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all

      0  

    Default


    See my suggestion in red color.
    Code:
    {
        xtype: 'actioncolumn',
        header: 'Enabled',
        id: 'TestActiveCol',
        dataIndex: 'enable',
        text: 'Enable',
        renderer: function(value, meta, rec){
            var items = this.down('actioncolumn[id=TestActiveCol]').items;
            if(rec.get('enable') == '0'){  // you can use value instead of rec.get('Active') eg if(value == 0) {
                items[0].icon = '../shared/icons/fam/add.gif';
                items[0].tooltip = 'Enable';
            } else {     
                 items[0].icon = '../shared/icons/fam/delete.gif';
                items[0].tooltip = 'Disable';
            }
        },
        handler: function(view, rowIndex){
            var record = store.getAt(rowIndex);
            record.set('enable', record.get('enable') == '0' ? '1' : '0');
        }

Thread Participants: 2

Tags for this Thread