简体   繁体   English

单元格模板中的AngularJS UI网格排序

[英]AngularJS ui-grid sorting in cellTemplate

I have a problem with the sort functionality in UI-GRID. 我对UI-GRID中的排序功能有疑问。 Currently I receive my data in this way: 目前,我以这种方式接收数据:

{
AccountID : 555,
Teacher: Somename,
SchoolName: 1
},

{
AccountID : 555,
Teacher: Somename,
SchoolName: 2
}

and etc. 等等。

I'm using a dictonary for my Schoolnames and I visualise them with: 我为学校名称使用了字典,并通过以下方式将其可视化:

if ( memberData.type == "dictionary" ) {
columnDef.cellTemplate = 
'<div class="ui-grid-cell-contents">
{{ grid.appScope.GetDictionaryItemValue( "' + memberData.dictionaryID + '", COL_FIELD ) }}
</div>';

The problem here is that the sorting function is sorting the schools not by the received from the dictonary name, but according their ID's. 这里的问题是排序功能不是根据字典名称接收到的学校,而是根据其ID对学校进行排序。

What would be the best solution to this problem? 什么是解决此问题的最佳方法?

I tried to use cellFilter instead of cellTemplate, but it also sort them by ID's. 我尝试使用cellFilter而不是cellTemplate,但是它也按ID对其进行排序。

Just tried again with cellFilter and actually it works this way: 刚刚再次尝试了cellFilter,实际上它是这样工作的:

columnDef.cellFilter = 'dictionaryFilter:"' + this + '"';

columnDef.sortCellFiltered = true;

Currently that is my filter code manually: 目前,这是我的手动过滤器代码:

 .filter( 'dictionaryFilter', function() {
        return function( input ) {


            if (input == 2) {
                input = 'High School';
            }
            if (input == 3) {
                input = 'Other School';
            }
            if (input == 16) {
                input = 'Another School';
            }

            return input;

        }

Is there a way to access the parent controller scope from this filter ? 有没有办法从此过滤器访问父控制器作用域? I do not want to hardcore the dictonary in the filter. 我不想在过滤器中使字典变得更硬。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM