【问题标题】:ng-grid headerCellTemplate for Filtering用于过滤的 ng-grid headerCellTemplate
【发布时间】:2014-12-23 14:59:19
【问题描述】:

对于使用 ng-grid 的过滤,我的意思是按列的 ng-grid 我以这个 plunker 为例,它工作正常 - http://plnkr.co/edit/c8mHmAXattallFRzXSaG?p=preview。但是,当我尝试制作自己的列过滤示例并根据 ng-grid 文档使用 var 时

var myHeaderCellTemplate = '<div class="ngHeaderSortColumn {{col.headerClass}}" ng-style="{cursor: col.cursor}" ng-class="{ ngSorted: !noSortVisible }">'+
                           '<div ng-click="col.sort($event)" ng-class="'colt' + col.index" class="ngHeaderText">{{col.displayName}}</div>'+
                           '<div class="ngSortButtonDown" ng-show="col.showSortButtonDown()"></div>'+
                           '<div class="ngSortButtonUp" ng-show="col.showSortButtonUp()"></div>'+
                           '<div class="ngSortPriority">{{col.sortPriority}}</div>'+
                         '</div>'+
                         '<div ng-show="col.resizable" class="ngHeaderGrip" ng-click="col.gripClick($event)" ng-mousedown="col.gripOnMouseDown($event)"></div>';

我在小马处不断收到语法错误。有人可以告诉我这里发生了什么吗?

【问题讨论】:

    标签: angularjs ng-grid


    【解决方案1】:

    您的模板字符串包括'

    '<div ng-click="col.sort($event)" ng-class="'colt' + col.index" class="ngHeaderText">{{col.displayName}}</div>'+
    

    你需要使用\,像这样

    '<div ng-click="col.sort($event)" ng-class="\'colt\' + col.index" class="ngHeaderText">{{col.displayName}}</div>'+
    

    编辑:

    如果需要过滤框,你错过这个

    <input type="text" ng-click="stopClickProp($event)" placeholder="Filter..." ng-model="col.filterText" ng-style="{ \'width\' : col.width - 14 + \'px\' }" style="position: absolute; top: 30px; bottom: 30px; left: 0; bottom:0;"/>
    

    这是一个例子

    Plunker

    编辑:

    最初的 plunkr 是从开头字符开始过滤的设计。如果您从子字符串中过滤,您可以尝试*开始过滤文本框。

    如果不喜欢,可以修改filterBarPlugin函数:

    var filterText = (col.filterText.indexOf('*') == 0 ? col.filterText.replace('*', '') : "^" + col.filterText) + ";";
    searchQuery += col.displayName + ": " + filterText;
    

    searchQuery += col.displayName + ": " + col.filterText;
    

    Example

    【讨论】:

    • 是的,我也这样做了,但是过滤器框不会出现。
    • 有没有办法让过滤发生在子字符串上而不是从开头字符开始。例如,当前如果您键入 S,它会在以 S 开头的列中显示数据,Sa 对于所有以 Sa 开头的数据。有没有办法让它过滤所有包含 Sa 的数据,而不仅仅是从它开始。
    猜你喜欢
    • 2015-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-24
    • 2014-09-09
    • 2014-11-25
    • 1970-01-01
    相关资源
    最近更新 更多