`
czpae86
  • 浏览: 713222 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

一个Ext.DataView / Ext.ListView扩展

 
阅读更多

在sencha论坛看到的扩展:


例子:

Ext.onReady(function() {
    new Ext.Viewport({
        layout: 'hbox',
        layoutConfig: {
            align: 'stretch'
        },
        defaults: {
            flex: 1
        },
        items: [{
            title: 'ComponentDataView example',
            items: {
                xtype: 'compdataview',
                store: [[1, 'One'], [2, 'Two'], [3, 'Three']],
                itemSelector: 'tbody tr',
                tpl: '<table><thead><tr><td>Value</td><td>Text</td></tr></thead><tbody><tpl for="."><tr><td></td><td></td></tr></tpl></tbody></table>',
                items: [{
                    xtype: 'numberfield',
                    minValue: 0,
                    maxValue: 100,
                    renderTarget: 'td:nth(1)',
                    applyValue: 'field1'
                },{
                    allowBlank: false,
                    renderTarget: 'td:nth(2)',
                    applyValue: 'field2'
                }]
            }
        },{
            title: 'ComponentListView example',
            items: {
                xtype: 'complistview',
                store: [[1, 'One'], [2, 'Two'], [3, 'Three']],
                columns: [{
                    header: 'Value',
                    width: .5,
                    dataIndex: 'field1',
                    tpl: ' ',
                    component: {
                        xtype: 'button',
                        text : 'test'
                    }
                },{
                    header: 'Text',
                    width: .5,
                    dataIndex: 'field2',
                    tpl: ' ',
                    component: {
                        allowBlank: false,
                        applyValue: true
                    }
                }]
            }
        }]
    });
});

 

扩展代码:

Ext.ns('Ext.ux');
Ext.ux.ComponentDataView = Ext.extend(Ext.DataView, {
    defaultType: 'textfield',
    initComponent : function(){
        Ext.ux.ComponentDataView.superclass.initComponent.call(this);
        this.components = [];
    },
    refresh : function(){
        Ext.destroy(this.components);
        this.components = [];
        Ext.ux.ComponentDataView.superclass.refresh.call(this);
        this.renderItems(0, this.store.getCount() - 1);
    },
    onUpdate : function(ds, record){
        var index = ds.indexOf(record);
        if(index > -1){
            this.destroyItems(index);
        }
        Ext.ux.ComponentDataView.superclass.onUpdate.apply(this, arguments);
        if(index > -1){
            this.renderItems(index, index);
        }
    },
    onAdd : function(ds, records, index){
        var count = this.all.getCount();
        Ext.ux.ComponentDataView.superclass.onAdd.apply(this, arguments);
        if(count !== 0){
            this.renderItems(index, index + records.length - 1);
        }
    },
    onRemove : function(ds, record, index){
        this.destroyItems(index);
        Ext.ux.ComponentDataView.superclass.onRemove.apply(this, arguments);
    },
    onDestroy : function(){
        Ext.ux.ComponentDataView.onDestroy.call(this);
        Ext.destroy(this.components);
        this.components = [];
    },
    renderItems : function(startIndex, endIndex){
        var ns = this.all.elements;
        var args = [startIndex, 0];
        for(var i = startIndex; i <= endIndex; i++){
            var r = args[args.length] = [];
            for(var items = this.items, j = 0, len = items.length, c; j < len; j++){
                c = items[j].render ?
                    c = items[j].cloneConfig() :
                    Ext.create(items[j], this.defaultType);
                r[j] = c;
                if(c.renderTarget){
                    c.render(Ext.DomQuery.selectNode(c.renderTarget, ns[i]));
                }else if(c.applyTarget){
                    c.applyToMarkup(Ext.DomQuery.selectNode(c.applyTarget, ns[i]));
                }else{
                    c.render(ns[i]);
                }
                if(Ext.isFunction(c.setValue) && c.applyValue){
                    c.setValue(this.store.getAt(i).get(c.applyValue));
                    c.on('blur', function(f){
                    	this.store.getAt(this.index).data[this.dataIndex] = f.getValue();
                    }, {store: this.store, index: i, dataIndex: c.applyValue});
                }
            }
        }
        this.components.splice.apply(this.components, args);
    },
    destroyItems : function(index){
        Ext.destroy(this.components[index]);
        this.components.splice(index, 1);
    }
});
Ext.reg('compdataview', Ext.ux.ComponentDataView);

Ext.ux.ComponentListView = Ext.extend(Ext.ListView, {
    defaultType: 'textfield',
    initComponent : function(){
        Ext.ux.ComponentListView.superclass.initComponent.call(this);
        this.components = [];
    },
    refresh : function(){
        Ext.destroy(this.components);
        this.components = [];
        Ext.ux.ComponentListView.superclass.refresh.apply(this, arguments);
        this.renderItems(0, this.store.getCount() - 1);
    },
    onUpdate : function(ds, record){
        var index = ds.indexOf(record);
        if(index > -1){
            this.destroyItems(index);
        }
        Ext.ux.ComponentListView.superclass.onUpdate.apply(this, arguments);
        if(index > -1){
            this.renderItems(index, index);
        }
    },
    onAdd : function(ds, records, index){
        var count = this.all.getCount();
        Ext.ux.ComponentListView.superclass.onAdd.apply(this, arguments);
        if(count !== 0){
            this.renderItems(index, index + records.length - 1);
        }
    },
    onRemove : function(ds, record, index){
        this.destroyItems(index);
        Ext.ux.ComponentListView.superclass.onRemove.apply(this, arguments);
    },
    onDestroy : function(){
        Ext.ux.ComponentDataView.onDestroy.call(this);
        Ext.destroy(this.components);
        this.components = [];
    },
    renderItems : function(startIndex, endIndex){
        var ns = this.all.elements;
        var args = [startIndex, 0];
        for(var i = startIndex; i <= endIndex; i++){
            var r = args[args.length] = [];
            for(var columns = this.columns, j = 0, len = columns.length, c; j < len; j++){
                var component = columns[j].component;
                c = component.render ?
                    c = component.cloneConfig() :
                    Ext.create(component, this.defaultType);
                r[j] = c;
                var node = ns[i].getElementsByTagName('dt')[j].firstChild;
                if(c.renderTarget){
                    c.render(Ext.DomQuery.selectNode(c.renderTarget, node));
                }else if(c.applyTarget){
                    c.applyToMarkup(Ext.DomQuery.selectNode(c.applyTarget, node));
                }else{
                    c.render(node);
                }
                if(c.applyValue === true){
                	c.applyValue = columns[j].dataIndex;
                }
                if(Ext.isFunction(c.setValue) && c.applyValue){
                    c.setValue(this.store.getAt(i).get(c.applyValue));
                    c.on('blur', function(f){
                    	this.store.getAt(this.index).data[this.dataIndex] = f.getValue();
                    }, {store: this.store, index: i, dataIndex: c.applyValue});
                }
            }
        }
        this.components.splice.apply(this.components, args);
    },
    destroyItems : function(index){
        Ext.destroy(this.components[index]);
        this.components.splice(index, 1);
    }
});
Ext.reg('complistview', Ext.ux.ComponentListView);

 

 

 

  • 大小: 12.1 KB
分享到:
评论

相关推荐

    Ext.DataView 图片列表显示

    var dataview = new Ext.DataView({ store: store, tpl : tpl, id: 'phones', itemSelector: 'li.phone', overClass : 'phone-hover', singleSelect: true, multiSelect : false, autoScroll : true }); ...

    jiaminghi/data-view dataV for vite2 vue3 windows补丁 for npm/yarn

    官网直接安装的不支持vite2+vue3的 主要修复: 1.build或者dev项目时不报错,兼容vite2,vue3; 2.加入deep监听watch,直接在父组件中修改图表中的config参数即可完成图表中的数据变更。 yarn npm cnpm pnpm可通用...

    jiaminghi/data-view dataV for vite2 vue3 windows补丁 for pnpm

    官网直接安装的不支持vite2+vue3的 主要修复: 1.build或者dev项目时不报错,兼容vite2,vue3; 2.加入deep监听watch,直接在父组件中修改图表中的config参数即可完成图表中的数据变更。 yarn npm cnpm pnpm可通用...

    dataview:查看 Flutter 的应用数据

    在一个链接中: import 'package:dataview/dataview.dart' ; // ... RaisedButton ( onPressed : () { Navigator . of (context). push ( MaterialPageRoute ( builder : (context) { return DataviewPage ( ...

    extjs dataview 显示图片 横向

    主要的四个文件 博文链接:https://zhao103804.iteye.com/blog/1884445

    SqlHelp.cs

    //返回DataView///6.public DataTable GetDataTableValue(string sql)//返回DataTable///7.public void ExecuteNonQuery(string sql)//执行一个SQL操作:添加、删除、更新操作 ///8.public int ExecuteNonQueryCount...

    基于RFID的门禁管理系统

    //dataView.append(ByteUtils.byteArrayToHexString(data,true) + "\r\n"); } } catch (Exception e) { ShowUtils.errorMessage(e.toString()); // 发生读取错误时显示错误信息后退出系统 System.exit(0); } ...

    C#集合Flash、数据库编程、以及Dataview、listview等的操作

    这个是我写的一个程序,里面集合C#多种操作,对于大家也许能起到一定的作用

    使用ajax局部刷新gridview进行数据绑定示例

    具体代码如下:  代码如下: &lt;&#37; @ Page Language = ” C# ” %&gt; &lt;!...&lt; script runat =”server” ... System.Data.DataView CreateDataSourceByXianhuiMeng() { System.Data.DataTable dt = new System

    chart3.jsp

    &lt;script src="./esl/esl.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;div id="main" style="height:400px"&gt;&lt;/div&gt; &lt;script type="text/javascript"&gt; var mydata = [20,3,50,10,20,30]; var mydata1 = [10,2,0,-3,12,20]; var...

    Flask_DataView.zip

    基于flask+pyecharts实现了一个图表大屏,基于ajax实现动态刷新数据。 教程地址:https://blog.csdn.net/pvlking/article/details/121249495

    Ext Touch 利用DataView 创建树形

    利用DataView 创建多选树形.。前台根据JSON创建node

    DataV Vue一款数据可视化应用搭建工具

    一款基于 Vue 3.0+, Vite 3.0+, Pinia 2.0+, TypeScript 4.0+, ECharts 5.0+数据可视化应用搭建工具

    Extjs图片展示组件实例

    漂亮的Extjs图片展示组件实例,类似于幻灯片,可直接拿去用,非常不错的哦

    C:\Users\Administrator\Desktop\高级消防员培训第一章.pptx

    高级消防员培训资料,有兴趣大家学习学习,高级消防员培训资料,有兴趣大家学习学习

    JAVA实现类似C#的DataTable数据结构_适用于安卓

    NULL 博文链接:https://zheyiw.iteye.com/blog/2039859

    。NET经典技术

    程序的学习是一个循序渐进的过程,一些常用的或经典代码应该保存下来以便日后使用。本文就给出一些.net的经典代码,希望对大家有所帮助……  1.弹出对话框.点击转向指定页面  Response.Write("");  Response....

    Ext 学习中文手册

    本文将简单地介绍Ext的几个基本概念,和如何快速地做出一个动态的页面并运行起来,假设读者已具备了一些JavaScript经验和初级了解HTML Dom。 目 录 EXT 中文手册 1 EXT简介 3 目錄 3 下载Ext 4 开始! 4 Element:...

    ext designer 设计实例

    ext designer 设计实例 实例包括form window grid listview panel dataview tabs

    hls.min.js

    !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define;.amd?define([],e):"object"==typeof exports?exports.Hls=e():t.Hls=e()}(this,...

Global site tag (gtag.js) - Google Analytics