Filter Data"
From Documentation
(Created page with "<!-- how to implement * toggle auto filter * clear * reapply --> Filter is a useful feature, when you want to focus on data.. <source lang='java'> public boolean isAutoFilt...") |
|||
Line 1: | Line 1: | ||
<!-- | <!-- | ||
− | how to | + | how to perform following task via API: |
* toggle auto filter | * toggle auto filter | ||
* clear | * clear | ||
* reapply | * reapply | ||
− | + | * apply criteria | |
--> | --> | ||
− | Filter is a useful feature, when you want to focus on data.. | + | Filter is a useful feature, when you want to focus on a subset of data. It can get rid of those data you don't want. Spreadsheet can allow you to enable / disable filter and apply / reset criteria via API. |
− | |||
− | |||
− | + | We'll use a simple application to demonstrate filter API. The screenshot is below: | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | [[File:zss-essentials-filter-example.png | center]] | |
− | |||
− | |||
− | + | In this application, we can toggle, clear, and reapply filter and filter by type column. | |
− | |||
− | |||
<source lang='java'> | <source lang='java'> | ||
− | + | public class AutoFilterComposer extends SelectorComposer<Component> { | |
− | + | @Wire | |
− | + | private Spreadsheet ss; | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | @Wire | ||
+ | private Combobox typeBox; | ||
+ | |||
+ | @Listen("onClick = button[label='Toogle Filter']") | ||
+ | public void toggle() { | ||
+ | Range selection = Ranges.range(ss.getSelectedSheet(), ss.getSelection()); | ||
+ | Range filterRange = selection.findAutoFilterRange(); | ||
+ | if(!selection.isAutoFilterEnabled() && filterRange == null) { | ||
+ | Messagebox.show("nothing to filter"); | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | selection.enableAutoFilter(!selection.isAutoFilterEnabled()); | ||
+ | } | ||
+ | |||
+ | @Listen("onClick = button[label='Clear Filter']") | ||
+ | public void clear() { | ||
+ | Range selection = Ranges.range(ss.getSelectedSheet(), ss.getSelection()); | ||
+ | selection.resetAutoFilter(); | ||
+ | } | ||
+ | |||
+ | @Listen("onClick = button[label='Reapply Filter']") | ||
+ | public void reapply() { | ||
+ | Range selection = Ranges.range(ss.getSelectedSheet(), ss.getSelection()); | ||
+ | selection.applyAutoFilter(); | ||
+ | } | ||
+ | |||
+ | @Listen("onClick = button[label='Apply']") | ||
+ | public void apply() { | ||
+ | Range currentSheet = Ranges.range(ss.getSelectedSheet()); | ||
+ | if (currentSheet.isAutoFilterEnabled()){ | ||
+ | String[] criteria = {typeBox.getValue()}; | ||
+ | currentSheet.enableAutoFilter(1, AutoFilterOperation.VALUES, criteria, null, true); | ||
+ | } | ||
+ | } | ||
+ | } | ||
</source> | </source> |
Revision as of 06:40, 8 October 2013
Filter is a useful feature, when you want to focus on a subset of data. It can get rid of those data you don't want. Spreadsheet can allow you to enable / disable filter and apply / reset criteria via API.
We'll use a simple application to demonstrate filter API. The screenshot is below:
In this application, we can toggle, clear, and reapply filter and filter by type column.
public class AutoFilterComposer extends SelectorComposer<Component> {
@Wire
private Spreadsheet ss;
@Wire
private Combobox typeBox;
@Listen("onClick = button[label='Toogle Filter']")
public void toggle() {
Range selection = Ranges.range(ss.getSelectedSheet(), ss.getSelection());
Range filterRange = selection.findAutoFilterRange();
if(!selection.isAutoFilterEnabled() && filterRange == null) {
Messagebox.show("nothing to filter");
return;
}
selection.enableAutoFilter(!selection.isAutoFilterEnabled());
}
@Listen("onClick = button[label='Clear Filter']")
public void clear() {
Range selection = Ranges.range(ss.getSelectedSheet(), ss.getSelection());
selection.resetAutoFilter();
}
@Listen("onClick = button[label='Reapply Filter']")
public void reapply() {
Range selection = Ranges.range(ss.getSelectedSheet(), ss.getSelection());
selection.applyAutoFilter();
}
@Listen("onClick = button[label='Apply']")
public void apply() {
Range currentSheet = Ranges.range(ss.getSelectedSheet());
if (currentSheet.isAutoFilterEnabled()){
String[] criteria = {typeBox.getValue()};
currentSheet.enableAutoFilter(1, AutoFilterOperation.VALUES, criteria, null, true);
}
}
}