shuishen
2021-06-08 b435f2b1fc2bc8ad392dfa78aed1a5bc70c8b1e4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
$.extend($.fn.datagrid.defaults.editors, {
    colorpicker: {//colorpicker就是你要自定义editor的名称
        init: function (container, options) {
            //var colorSector = $('<div id="colorSelector" class="colorSelector">').appendTo(container);
            //$('#colorSelector').ColorPicker({
            //    color: '#0000ff',
            //    onShow: function (colpkr) {
            //        $(colpkr).fadeIn(500);
            //        return false;
            //    },
            //    onHide: function (colpkr) {
            //        $(colpkr).fadeOut(500);
            //        return false;
            //    },
            //    onChange: function (hsb, hex, rgb) {
            //        $('#colorSelector div').css('backgroundColor', '#' + hex);
            //    }
            //});
            //
            //return $('#colorSelector div');
            var input = $('<input>').appendTo(container);
            input.ColorPicker({
                color: '#0000ff',
                onShow: function (colpkr) {
                    $(colpkr).fadeIn(500);
                    return false;
                },
                onHide: function (colpkr) {
                    $(colpkr).fadeOut(500);
                    return false;
                },
                onChange: function (hsb, hex, rgb) {
                    input.css('backgroundColor', '#' + hex);
                    input.val('0x' + hex);
                }
            });
            return input;
        },
        getValue: function (target) {
            return $(target).val().replace(/0x/, "#");
        },
        setValue: function (target, value) {
            // 特殊处理, 因为在flash里使用的是0x16进制格式
            value = value.replace(/0x/, "#");
            $(target).val(value);
            $(target).css('backgroundColor', value);
            $(target).ColorPickerSetColor(value);
        },
        resize: function (target, width) {
            var input = $(target);
            if ($.boxModel == true) {
                input.width(width - (input.outerWidth() - input.width()));
            } else {
                input.width(width);
            }
        }
    }
});