본문 바로가기

js/jsGrid

[jsgrid] custom type 만들기



var defaultFields = [
    { name: "Title", type: "text", width: "", title: "제목", css : "col-md-4 col-sm-4 col-xs-4" },
    { name: "MenuType_Code", type: "text", width: "", title: "위치", css : "text-center" },
    { name: "Location_Code", type: "text", width: "", title: "순서", css: "text-center" },
    { name: "Region_Code", type: "text", width: "", title: "지역", css: "text-center" },
    { name: "Start_Date", type: "date", width: "", title: "게시시작", css: "text-center" },
    { name: "End_Date", type: "date", width: "", title: "게시종료", css: "text-center" },
    { name: "Image", type: "text", width: "", title: "이미지", css: "text-center" },
    { name: "Url", type: "url", width: "", title: "링크", css: "text-center" },
    { name: "Status_Code", type: "text", width: "", title: "진행상태", css: "text-center" }
];


var DateField = function (config) {
    jsGrid.Field.call(this, config);
};

var UrlField = function (config) {
    jsGrid.Field.call(this, config);
};

DateField.prototype = new jsGrid.Field({
    itemTemplate: function (value) {
        return new Date(value.match(/\d+/)[0] * 1).format("yyyy-MM-dd");
    }
});

UrlField.prototype = new jsGrid.Field({
    itemTemplate: function (value) {
        if (value !== "N")
            return "<a href=\"" + value + "\" target=\"_blank\">Y</a>";
        else
            return "N";
    }
});

jsGrid.fields.date = DateField;
jsGrid.fields.url = UrlField;