Constructing fuelux datagrid datasource with custom backbone collection

时光毁灭记忆、已成空白 提交于 2019-12-05 19:21:46

I was stucking around datasource. I modified the datasource as follows and then it worked.

var StaticDataSource = function (options) {
    this._formatter = options.formatter;
    this._columns = options.columns;
    this._delay = options.delay || 0;
    this._data = options.data;
};

StaticDataSource.prototype = {

    columns: function () {
        return this._columns;
    },

    data: function (options, callback) {
        var self = this;

        setTimeout(function () {
            var data = $.extend(true, [], self._data);

            // SEARCHING
            if (options.search) {
                data = _.filter(data, function (item) {
                    var match = false;

                    _.each(item, function (prop) {
                        if (_.isString(prop) || _.isFinite(prop)) {
                            if (prop.toString().toLowerCase().indexOf(options.search.toLowerCase()) !== -1) match = true;
                        }
                    });

                    return match;
                });
            }

            // FILTERING
            if (options.filter) {
                data = _.filter(data, function (item) {
                    switch(options.filter.value) {
                        case 'lt5m':
                            if(item.population < 5000000) return true;
                            break;
                        case 'gte5m':
                            if(item.population >= 5000000) return true;
                            break;
                        default:
                            return true;
                            break;
                    }
                });
            }

            var count = data.length;

            // SORTING
            if (options.sortProperty) {
                data = _.sortBy(data, options.sortProperty);
                if (options.sortDirection === 'desc') data.reverse();
            }

            // PAGING
            var startIndex = options.pageIndex * options.pageSize;
            var endIndex = startIndex + options.pageSize;
            var end = (endIndex > count) ? count : endIndex;
            var pages = Math.ceil(count / options.pageSize);
            var page = options.pageIndex + 1;
            var start = startIndex + 1;

            data = data.slice(startIndex, endIndex);

            if (self._formatter) self._formatter(data);

            callback({ data: data, start: start, end: end, count: count, pages: pages, page: page });

        }, this._delay)
    }
};

Infact, I just removed following code and its associated braces.

(function (root, factory) {
if (typeof define === 'function' && define.amd) {
    define(['underscore'], factory);
} else {
    root.StaticDataSource = factory();
}
}(this, function () {

I dont know what exactly the above code is doing an what dependdencies they have over.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!