Slickgrid筛选器,用于格式化的单元格内容 [英] Slickgrid filter on formatted cell content

查看:293
本文介绍了Slickgrid筛选器,用于格式化的单元格内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于一个新项目,我们使用SlickGrid,这是一个非常整洁的工具,用于显示网格数据.我们正在尝试在网格上方实现一个搜索框,以对网格内容进行过滤.我们正在将DataView与网格一起使用,并且可以使用函数'setFilter'和'setFilterArgs'在DataView上实现过滤器.

For a new project we are using SlickGrid which is a very neat tool for displaying grid data. We are trying to implement a search box above the grid which filter the content of the grid. We're using a DataView with the grid and we can use the functions 'setFilter' and 'setFilterArgs' to implement the filter on the DataView.

我们还使用自定义格式器来格式化某些字段的单元格内容.例如,国家/地区是我们数据对象中的国家/地区代码(例如'NL'),但是我们在网格列定义中使用格式器将其显示为转换后的值'Netherlands'.日期也以这种方式格式化.

We also use custom formatters to format the content of the cells for some fields. For example the country is a country code in our data object (for example 'NL') but we use a formatter in the grid column definitions to display it as the translated value 'Netherlands'. Also dates are formatted this way.

问题是:我们只能对数据对象中的内容进行过滤,因为它可以从DataView中访问,但是我们需要对网格中单元格中显示的格式化内容进行过滤.有什么方法可以快速,良好地完成此任务吗?

The problem is: We can only filter on the content in the data object because it is accessible from the DataView, but we need to filter on the formatted content which is presented in the cells by the grid. Is there any way to get this done in a fast and good way ?

推荐答案

CPU有效方式:在格式化程序函数中,在return语句之前分配:

CPU efficient way: in your formatter function, assign, just before your return statement:

dataContext.countryName = myFullCountryName;

这将为项目/行添加一个新属性.然后,当您在country列上进行排序时,只需引用countryName即可.

This will add a new property to the item/row. Then when you're sorting on the country column, simply reference the countryName instead.

内存高效的方法是,在排序功能进行比较之前,只需通过格式化程序功能传递每个国家/地区的值即可.

The memory efficient way would be to simply pass each country value through your formatter function before doing the comparison in your sorting function.

这篇关于Slickgrid筛选器,用于格式化的单元格内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆