NGridTable.js 1.99 KB
define(["utils"], function (_u) {
    'use strict';

    function NGridTable() {
        this.store = {};
    }

    NGridTable.prototype = {
        transferToVM: function (dm) {
            var btns = dm.customBtns || [],
                sourceData = dm.sourceData || {},
                sourceType = sourceData.sourceType;
            var gtHeight = "height:auto;";
            var autoHeight = true;
            var fixedColumn = 0;
            var cols = dm.showColumns.map(function (d, i) {
                return {
                    text: d.fieldTitle,
                    width: d.fieldWidth && _u.toPixel(d.fieldWidth, "width"),
                    fixedColumn: i < fixedColumn
                };
            });

            if(dm.gtHeight) {
                gtHeight = _u.toPixel(dm.gtHeight, "height");
                autoHeight = false;
            }

            return {
                dataSource: {
                    type: sourceType == 1 ? 'cube' : 'other'
                },
                quickSearch: {
                    hide: dm.quickSearch !== "1",
                    tip: dm.searchTips
                },
                advancedSearch: {
                    enable: sourceType == 1 && dm.advancedSearch == 1,
                },
                btns: btns.map(function (btn) {
                    var btnType = btn.btnType, picPath = btn.picPath || "", btnText = btn.btnText || "";
                    return {
                        type: btnType,
                        icon: btnType == "1" ? "" : picPath,
                        text: btnType == "2" ? "" : btnText
                    };
                }),
                options: {
                    width: _u.toPixel(dm.gtWidth || "100%", "width"),
                    height: gtHeight,
                    autoHeight: autoHeight,
                },
                headerView: {
                    normal: cols,
                    fixed: cols.slice(0, fixedColumn)
                }
            }
        }
    };

    return NGridTable;
});