Flex动态生成可编辑的DataGrid


Flex #datagrid2014-04-10 09:46
具有的功能 
1、表头是动态生成的。 
2、每行都是有序号的。 
3、每行都是可以编辑、插入、删除、修改的。 
4、每个单元格都是加验证的。 

5、单元格有些是经过渲染生成的比如:Combobox,DateField... 

代码如下

package datagridview {
    import com.adobe.serialization.json.JSON;
    import com.jzh.test.ComboxColumn;
    import com.jzh.test.ComboxItem;
    import mx.collections.ArrayCollection;
    import mx.controls.Alert;
    import mx.controls.ComboBase;
    import mx.controls.ComboBox;
    import mx.controls.DateField;
    import mx.controls.RadioButtonGroup;
    import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
    import mx.core.ClassFactory;
    import mx.validators.RegExpValidator;
    import spark.components.DropDownList;
    public class RendererUtil {
        public
        function RendererUtil() {}
        public static
        function getButtonRenderer() : ClassFactory {
            var f: ClassFactory = new ClassFactory(OperateButtons);
            f.properties = {};
            return f;
        }
        public static
        function getNumRenderer() : ClassFactory {
            var f: ClassFactory = new ClassFactory(numLabel);
            f.properties = {};
            return f;
        }
        public static
        function getComboxRenderer(arr: ArrayCollection, label: String) : ClassFactory {
            //应该在这里查询数据库 
            var f: ClassFactory = new ClassFactory(ComboBox);
            f.properties = {
                dataProvider: arr,
                labelField: label,
                selectedIndex: '0',
                selectedItem: '石质路面'
            }; //添加属性,绑定选择状态 
            return f;
        }
        public static
        function getRadioRenderer(label: String) : ClassFactory {
            var f: ClassFactory = new ClassFactory(ComboBox);
            var arr: ArrayCollection = new ArrayCollection();
            arr.addItem("是");
            arr.addItem("否");
            f.properties = {
                dataProvider: arr,
                labelField: label,
                selectedIndex: '0',
                selectedItem: '否'
            }; //添加属性,绑定选择状态 
            return f;
        }
        public static
        function getDateRenderer() : ClassFactory {
            var f: ClassFactory = new ClassFactory(DateField);
            f.properties = {
                formatString: "YYYY-MM-DD",
                showToday: true
            }; //添加属性,绑定选择状态 
            return f;
        }
        /*http://yige.org/*/
        public static
        function getValidateRenderer() : ClassFactory {
            var f: ClassFactory = new ClassFactory(RegExpValidator);
            f.properties = {
                source: "roadcode",
                property: "text",
                expression: "^[0-9]*$",
                noMatchError: "填写验证不通过时显示他提示信息"
            }; //添加属性,绑定选择状态 
            return f;
        }
        /*测试用*/
        public static
        function getRenderer(label: String, callback: Function = null) : ClassFactory {
            var f: ClassFactory = new ClassFactory(numLabel);
            f.properties = {
                lab: label,
                callback: callback
            };
            return f;
        }
    }
}


相关文章

粤ICP备11097351号-1