javascript - 多选复选框不返回 Extjs 4.2 网格中的值

标签 javascript jquery extjs

我正在为我的应用程序使用 Extjs 4.2 网格。在我的网格中,有一个选项可以选择多行并删除它们(通过复选框)。但我只是选择的行没有返回任何值。

下面是我的代码..

################################################## #########################
Ext.Loader.setConfig({enabled: true});

Ext.Loader.setPath('Ext.ux', '../js/extjs_4_2/examples/ux/');
Ext.require([
    'Ext.grid.*',
    'Ext.data.*',
    'Ext.util.*',
    'Ext.ux.grid.FiltersFeature',
    'Ext.toolbar.Paging',
    'Ext.ux.PreviewPlugin',
    'Ext.ModelManager',
    'Ext.tip.QuickTipManager',
    'Ext.selection.CheckboxModel'
]);

Ext.onReady(function(){
Ext.tip.QuickTipManager.init();

Ext.define('ForumThread', {
    extend: 'Ext.data.Model',
   fields: [

       {name: 'patient_name'},
       {name: 'referrer_provider'},
       {name: 'admit_date'},
       {name: 'added_date'},                  
               {name: 'billing_date'},
       {name: 'dob'},
               {name: 'loc_name'},
       {name: 'physician_name'},
       {name: 'imploded_diagnosis_name'},                  
               {name: 'imploded_procedure_name'},
       {name: 'imploded_optional_name'},
       {name: 'imploded_quick_list_name'},
       {name: 'med_record_no'},
               {name: 'message'}
            ],

    idProperty: 'bill_id'
});

var url = {
    remote: '../new_charges_json.php'
};
// configure whether filter query is encoded or not (initially)
var encode = false;
// configure whether filtering is performed locally or remotely (initially)
var local = false;

// create the Data Store
var store = Ext.create('Ext.data.Store', {
    pageSize: 10,
    model: 'ForumThread',
    remoteSort: true,
    proxy: {
        type: 'jsonp',
        url: (local ? url.local : url.remote),
        reader: {
            root: 'charges_details',
            totalProperty: 'total_count'
        },
        simpleSortMode: true
    },
    sorters: [{
        property: 'patient_name',
        direction: 'DESC'
    }]
});

    var filters = {
    ftype: 'filters',
    // encode and local configuration options defined previously for easier reuse
    encode: encode, // json encode the filter query
    local: local,   // defaults to false (remote filtering)

    // Filters are most naturally placed in the column definition, but can also be
    // added here.
    filters: [{
        type: 'string',
        dataIndex: 'patient_name'
    }]
};

// use a factory method to reduce code while demonstrating
// that the GridFilter plugin may be configured with or without
// the filter types (the filters may be specified on the column model

var createColumns = function (finish, start) {

    var columns = [
        {
            menuDisabled: true,
            sortable: false,
            xtype: 'actioncolumn',
            width: 50,


            items: [{
                icon   : '../js/extjs_4_2/examples/shared/icons/fam/user_profile.png',  // Use a URL in the icon config
                tooltip: 'Patient Profile',
                renderer: renderTopic,
                handler: function(grid, rowIndex, colIndex) {
                    var rec = store.getAt(rowIndex);
                    //alert("Bill Id: " + rec.get('bill_id'));
                    //Ext.Msg.alert('Bill Info', rec.get('patient_name')+ ", Bill Id: " +rec.get('bill_id'));
                    window.location.href="../newdash/profile.php?bill_id="+rec.get('bill_id');
                }
            }, 
        ]
        },
        {
        dataIndex: 'patient_name',
        text: 'Patient Name',
        sortable: true,
        // instead of specifying filter config just specify filterable=true
        // to use store's field's type property (if type property not
        // explicitly specified in store config it will be 'auto' which
        // GridFilters will assume to be 'StringFilter'
        filterable: true
        //,filter: {type: 'numeric'}
    }, {
        dataIndex: 'referrer_provider',
        text: 'Referring',
        sortable: true
        //flex: 1,
    }, {
        dataIndex: 'admit_date',
        text: 'Admit date',
    }, {
        dataIndex: 'added_date',
        text: 'Sign-on date'
    }, {
        dataIndex: 'billing_date',
        text: 'Date Of Service',
        filter: true,
        renderer: Ext.util.Format.dateRenderer('m/d/Y')
    }, {
        dataIndex: 'dob',
        text: 'DOB'
        // this column's filter is defined in the filters feature config
    },{
        dataIndex: 'loc_name',
        text: 'Location',
        sortable: true
    },{
        dataIndex: 'physician_name',
        text: 'Physician (BILLED)',
        sortable: true
    },{
        dataIndex: 'imploded_diagnosis_name',
        text: 'Diagnosis'
    },{
        dataIndex: 'imploded_procedure_name',
        text: 'Procedure'
    },{
        dataIndex: 'imploded_optional_name',
        text: 'OPT Template'
    },{
        dataIndex: 'imploded_quick_list_name',
        text: 'Quick List'
    },{
        dataIndex: 'med_record_no',
        text: 'Medical Record Number'
    },{
        dataIndex: 'message',
        text: 'TEXT or NOTES'
    }



    ];

    return columns.slice(start || 0, finish);
};


var pluginExpanded = true;


var selModel = Ext.create('Ext.selection.CheckboxModel', {

        columns: [
        {xtype : 'checkcolumn', text : 'Active', dataIndex : 'bill_id'}
        ],
    checkOnly: true,
    mode: 'multi',
    enableKeyNav: false,


    listeners: {
        selectionchange: function(sm, selections) {
            grid.down('#removeButton').setDisabled(selections.length === 0);
        }
    }
});

var grid = Ext.create('Ext.grid.Panel', {
    //width: 1024,
    height: 500,
    title: 'Charge Information',
    store: store,
    //disableSelection: true,
    loadMask: true,
    features: [filters],
    forceFit: true,
    viewConfig: {
        stripeRows: true,
        enableTextSelection: true
    },
    // grid columns
    colModel: createColumns(15),

    selModel: selModel,

    // inline buttons
    dockedItems: [
       {
        xtype: 'toolbar',
        items: [{
            itemId: 'removeButton',
            text:'Charge Batch',
            tooltip:'Charge Batch',
            disabled: false,
            enableToggle: true,
    toggleHandler: function() {  // Here goes the delete functionality
                alert(selModel.getCount());
                var selected = selModel.getView().getSelectionModel().getSelections();
                alert(selected.length);
                var selectedIds;
                if(selected.length>0) {
                    for(var i=0;i<selected.length;i++) {
                        if(i==0)
                        {
                                selectedIds = selected[i].get("bill_id");
                        }   
                        else
                        {
                                selectedIds = selectedIds + "," + selected[i].get("bill_id");
                        }
                    }
                }

                alert("Seleted Id's: "+selectedIds);return false;

            }









        }]
    }],



    // paging bar on the bottom
        bbar: Ext.create('Ext.PagingToolbar', {
        store: store,
        displayInfo: true,
        displayMsg: 'Displaying charges {0} - {1} of {2}',
        emptyMsg: "No charges to display"
    }),
    renderTo: 'charges-paging-grid'
});

store.loadPage(1);
});
#

它在所选行的警报对话框中给出数字,这里 警报(selModel.getCount()); 但在此之后它在下面的行中抛出一个javascript错误“selModel.getView不是一个函数” var selected = selModel.getView().getSelectionModel().getSelections(); 我将其更改为 var selected = grid.getView().getSelectionModel().getSelections();它仍然抛出相同类型的错误(grid.getView 不是函数)。

最佳答案

试试这个

var selected = selModel.getSelection();

而不是这个

var selected = selModel.getSelectionModel().getSelections();

关于javascript - 多选复选框不返回 Extjs 4.2 网格中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18587850/

相关文章:

javascript - 单击按钮对 AngularJS 中的 json 对象列表进行排序

jQuery 按类获取元素

javascript - 如何将 &autoplay=1 动态添加到 youtube 嵌入代码?

javascript - CompositeField 上的自定义 FieldLabel

javascript - 处理 Rally 数据存储中的空异常

extjs - 如何设置组合框的动态高度

javascript - 在 Facebook iframe 滚动条或页面中途 chop 之间进行选择

javascript - 如何仅针对Angular7中的字母数字和特殊字符触发keydown事件?

jquery - 如何使 CSS Toggle 像这样?

javascript - 正则表达式匹配完整单词,但在第一次失败时完全不匹配