summaryrefslogtreecommitdiffhomepage
path: root/examples/sort_state_example.md
diff options
context:
space:
mode:
Diffstat (limited to 'examples/sort_state_example.md')
-rw-r--r--examples/sort_state_example.md42
1 files changed, 42 insertions, 0 deletions
diff --git a/examples/sort_state_example.md b/examples/sort_state_example.md
new file mode 100644
index 00000000..d0258c31
--- /dev/null
+++ b/examples/sort_state_example.md
@@ -0,0 +1,42 @@
+## Description
+
+You could add sort conditions to the sort state of an auto filtered table
+
+## Code
+
+```ruby
+require 'axlsx'
+
+p = Axlsx::Package.new
+wb = p.workbook
+
+wb.add_worksheet(name: 'Sort State') do |sheet|
+ sheet.add_row ['Number', 'Letter', 'Priority']
+ sheet.add_row [1, 'B', 'high']
+ sheet.add_row [2, 'B', 'low']
+ sheet.add_row [3, 'B', 'medium']
+ sheet.add_row [4, 'B', 'high']
+ sheet.add_row [5, 'B', 'low']
+ sheet.add_row [6, 'B', 'medium']
+ sheet.add_row [7, 'A', 'high']
+ sheet.add_row [8, 'A', 'low']
+ sheet.add_row [9, 'A', 'medium']
+ sheet.add_row [10, 'A', 'high']
+ sheet.add_row [11, 'A', 'low']
+ sheet.add_row [12, 'A', 'medium']
+ sheet.auto_filter = 'A1:C13'
+ sheet.auto_filter.sort_state.add_sort_condition column_index: 1
+ sheet.auto_filter.sort_state.add_sort_condition column_index: 2, custom_list: ['low', 'medium', 'high']
+ sheet.auto_filter.sort_state.add_sort_condition column_index: 0, order: :desc
+end
+
+p.serialize 'sort_state_example.xlsx'
+```
+
+## Output
+
+![Output](images/sort_state_example_1.png "Output")
+
+After adding the sort conditions:
+
+![Output](images/sort_state_example_2.png "Output")