Skip to content

Commit 09b9b8d

Browse files
committed
fix: selection plugin
1 parent a45845d commit 09b9b8d

2 files changed

Lines changed: 5 additions & 100 deletions

File tree

docs/plugins/selection/row-selection.md

Lines changed: 1 addition & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ const grid = new Grid({
3535
plugin: {
3636
// install the RowSelection plugin
3737
component: RowSelection,
38-
// RowSelection config
39-
props: {
40-
// use the "email" column as the row identifier
41-
id: (row) => row.cell(2).data
42-
}
4338
}
4439
},
4540
{
@@ -79,10 +74,7 @@ const grid = new Grid({
7974
// select all rows by default!
8075
data: () => true,
8176
plugin: {
82-
component: RowSelection,
83-
props: {
84-
id: (row) => row.cell(2).data
85-
}
77+
component: RowSelection
8678
}
8779
},
8880
{
@@ -107,85 +99,6 @@ grid.on('ready', () => {
10799
`
108100
} scope={{RowSelection}} />
109101

110-
## Row selection extension
111-
112-
Grid.js enables you to write custom plugins and extend the core functionality. In this example, we are developing a custom
113-
plugin which listens to the Selection plugin events and populates a list of selected rows.
114-
115-
116-
<LiveExample children={
117-
`
118-
class SelectionsList extends BaseComponent {
119-
constructor(props, context) {
120-
super(props, context);
121-
122-
this.state = {
123-
selectedRows: []
124-
};
125-
}
126-
127-
componentDidMount() {
128-
const grid = this.config.instance;
129-
130-
grid.on('ready', () => {
131-
// find the plugin with the give plugin ID
132-
const checkboxPlugin = this.config.plugin.get('selectRow');
133-
134-
// subscribe to the store events
135-
checkboxPlugin.props.store.on('updated', (state) => {
136-
this.setState({
137-
selectedRows: state.rowIds
138-
});
139-
});
140-
});
141-
}
142-
143-
render() {
144-
if (!this.state.selectedRows.length) {
145-
return h('b', {}, 'Select some rows...');
146-
}
147-
148-
return h(
149-
'ul',
150-
{},
151-
this.state.selectedRows.map((rowId) => h('li', {}, rowId))
152-
);
153-
}
154-
}
155-
156-
const grid = new Grid({
157-
columns: [
158-
{
159-
id: 'selectRow',
160-
name: 'Select',
161-
plugin: {
162-
component: RowSelection,
163-
props: {
164-
id: (row) => row.cell(2).data
165-
}
166-
}
167-
},
168-
{
169-
name: 'Name',
170-
formatter: (cell) => \`Name: \${cell}\`
171-
},
172-
'Email',
173-
],
174-
sort: true,
175-
data: Array(5).fill().map(x => [
176-
faker.name.findName(),
177-
faker.internet.email(),
178-
])
179-
});
180-
181-
grid.plugin.add({
182-
id: 'selectionsList',
183-
component: SelectionsList,
184-
position: PluginPosition.Footer,
185-
});
186-
`
187-
} scope={{RowSelection}} />
188-
189102
:::tip
190103
Follow the [Advanced Plugin](../advanced-plugins.md) article to learn more about writing Grid.js plugins!
191104
:::

docs/plugins/selection/selection-events.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ const grid = new Grid({
2626
id: 'awesomeCheckbox',
2727
name: 'Select',
2828
plugin: {
29-
component: RowSelection,
30-
props: {
31-
id: (row) => row.cell(2).data
32-
}
29+
component: RowSelection
3330
}
3431
},
3532
{
@@ -45,14 +42,9 @@ const grid = new Grid({
4542
])
4643
});
4744

48-
grid.on('ready', () => {
49-
// find the plugin with the give plugin ID
50-
const checkboxPlugin = grid.config.plugin.get('awesomeCheckbox');
51-
52-
// subscribe to the store events
53-
checkboxPlugin.props.store.on('updated', function (state, prevState) {
54-
console.log('checkbox updated', state, prevState);
55-
});
45+
// subscribe to the store events
46+
grid.config.store.subscribe(function (state) {
47+
console.log('checkbox updated', state.rowSelection);
5648
})
5749
`
5850
} scope={{RowSelection}} />

0 commit comments

Comments
 (0)