xmlgridscript.cs

来自「经典编程900例(C语言),主要是C基础知识」· CS 代码 · 共 59 行

CS
59
字号
using System;
using Ext;
using Ext.data;
using Ext.grid;
using ScriptFX;

namespace SampleScripts.grid {
    public class XmlGridScript {
        public static void main(Dictionary args) {
            ExtClass.onReady(new AnonymousDelegate(delegate() { new XmlGridScript().init(); }));
        }

        public void init() {

            // create the Data Store
            Store ds = new Store(new StoreConfig()
                // load using HTTP
                .url("sheldon.xml")

                // the return will be XML, so lets set up a reader
                .reader(new XmlReader(
                    new XmlReaderConfig()
                        // records will have an "Item" tag
                        .record("Item")
                        .id("ASIN")
                        .totalRecords("@total")
                        .ToDictionary(),                     
                    new object[] {
                       // set up the fields mapping into the xml doc
                       // The first needs mapping, the others are very basic
                        new Dictionary("name", "Author", "mapping", "ItemAttributes > Author"),
                        "Title", "Manufacturer", "ProductGroup"
                    }))
                .ToDictionary()
            );

            ColumnModel cm = new ColumnModel(new Dictionary[] {
                new ColumnModelConfig().header("Author").width(120).dataIndex("Author").ToDictionary(),
                new ColumnModelConfig().header("Title").width(180).dataIndex("Title").ToDictionary(),
                new ColumnModelConfig().header("Manufacturer").width(115).dataIndex("Manufacturer").ToDictionary(),
                new ColumnModelConfig().header("Product Group").width(100).dataIndex("ProductGroup").ToDictionary()
            });
            cm.defaultSortable = true;

            // create the grid
            Ext.grid.GridPanel grid = new Ext.grid.GridPanel(new Ext.grid.GridPanelConfig()
                .ds(ds)
                .cm(cm)
                .renderTo("example-grid")
                .width(540)
                .height(200)
                .ToDictionary()
            );

            ds.load();
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?