Skip to content

Commit 7612e2c

Browse files
authored
Merge pull request #211 from quantopian/edit-cell-docs
Add doc string for the edit_cell method
2 parents f0d9dfe + 050fc01 commit 7612e2c

5 files changed

Lines changed: 50 additions & 15 deletions

File tree

js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "qgrid",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "An Interactive Grid for Sorting and Filtering DataFrames in Jupyter Notebook",
55
"author": "Quantopian Inc.",
66
"main": "src/index.js",

js/src/qgrid.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@
155155
height: 315px !important;
156156
}
157157

158+
.q-grid-toolbar {
159+
display: none;
160+
}
161+
162+
.show-toolbar .q-grid-toolbar {
163+
display: block;
164+
}
165+
158166
.output_scroll .show-toolbar .q-grid {
159167
height: 284px !important;
160168
}

js/src/qgrid.widget.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class QgridModel extends widgets.DOMWidgetModel {
3636
_view_name : 'QgridView',
3737
_model_module : 'qgrid',
3838
_view_module : 'qgrid',
39-
_model_module_version : '^1.1.0',
40-
_view_module_version : '^1.1.0',
39+
_model_module_version : '^1.1.1',
40+
_view_module_version : '^1.1.1',
4141
_df_json: '',
4242
_columns: {}
4343
});
@@ -62,16 +62,21 @@ class QgridView extends widgets.DOMWidgetView {
6262
if (!this.$el.hasClass('q-grid-container')){
6363
this.$el.addClass('q-grid-container');
6464
}
65-
66-
if (this.model.get('show_toolbar')) {
67-
this.initialize_toolbar();
68-
}
69-
65+
this.initialize_toolbar();
7066
this.initialize_slick_grid();
7167
}
7268

7369
initialize_toolbar() {
74-
this.$el.addClass('show-toolbar');
70+
if (!this.model.get('show_toolbar')){
71+
this.$el.removeClass('show-toolbar');
72+
} else {
73+
this.$el.addClass('show-toolbar');
74+
}
75+
76+
if (this.toolbar){
77+
return;
78+
}
79+
7580
this.toolbar = $("<div class='q-grid-toolbar'>").appendTo(this.$el);
7681

7782
let append_btn = (btn_info) => {
@@ -196,7 +201,10 @@ class QgridView extends widgets.DOMWidgetView {
196201
* type of data in the columns of the DataFrame provided by the user.
197202
*/
198203
initialize_slick_grid() {
199-
this.grid_elem = $("<div class='q-grid'>").appendTo(this.$el);
204+
205+
if (!this.grid_elem) {
206+
this.grid_elem = $("<div class='q-grid'>").appendTo(this.$el);
207+
}
200208

201209
// create the table
202210
var df_json = JSON.parse(this.model.get('_df_json'));
@@ -391,6 +399,7 @@ class QgridView extends widgets.DOMWidgetView {
391399
this.columns,
392400
this.grid_options
393401
);
402+
this.grid_elem.data('slickgrid', this.slick_grid);
394403

395404
if (this.grid_options.forceFitColumns){
396405
this.grid_elem.addClass('force-fit-columns');
@@ -414,6 +423,8 @@ class QgridView extends widgets.DOMWidgetView {
414423
this.slick_grid.setSelectionModel(new Slick.RowSelectionModel());
415424
this.slick_grid.setCellCssStyles("grouping", this.row_styles);
416425
this.slick_grid.render();
426+
427+
this.update_size();
417428

418429
var render_header_cell = (e, args) => {
419430
var cur_filter = this.filters[args.column.id];
@@ -664,7 +675,7 @@ class QgridView extends widgets.DOMWidgetView {
664675
*/
665676
handle_msg(msg) {
666677
if (msg.type === 'draw_table') {
667-
this.initialize_qgrid();
678+
this.initialize_slick_grid();
668679
} else if (msg.type == 'show_error') {
669680
alert(msg.error_msg);
670681
if (msg.triggered_by == 'add_row' ||
@@ -773,6 +784,8 @@ class QgridView extends widgets.DOMWidgetView {
773784
this.slick_grid.scrollRowIntoView(msg.rows[0]);
774785
}
775786
this.ignore_selection_changed = false;
787+
} else if (msg.type == 'change_show_toolbar') {
788+
this.initialize_toolbar();
776789
} else if (msg.col_info) {
777790
var filter = this.filters[msg.col_info.name];
778791
filter.handle_msg(msg);

qgrid/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version_info = (1, 1, 0, 'final')
1+
version_info = (1, 1, 1, 'final')
22

33
_specifier_ = {'alpha': 'a', 'beta': 'b', 'candidate': 'rc', 'final': ''}
44

qgrid/grid.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,8 @@ class can be constructed directly but that's not recommended because
566566
_model_name = Unicode('QgridModel').tag(sync=True)
567567
_view_module = Unicode('qgrid').tag(sync=True)
568568
_model_module = Unicode('qgrid').tag(sync=True)
569-
_view_module_version = Unicode('1.1.0').tag(sync=True)
570-
_model_module_version = Unicode('1.1.0').tag(sync=True)
569+
_view_module_version = Unicode('1.1.1').tag(sync=True)
570+
_model_module_version = Unicode('1.1.1').tag(sync=True)
571571

572572
_df = Instance(pd.DataFrame)
573573
_df_json = Unicode('', sync=True)
@@ -843,7 +843,7 @@ def _grid_options_changed(self):
843843
def _show_toolbar_changed(self):
844844
if not self._initialized:
845845
return
846-
self._rebuild_widget()
846+
self.send({'type': 'change_show_toolbar'})
847847

848848
def _update_table(self,
849849
update_columns=False,
@@ -1689,6 +1689,20 @@ def _add_row(self, row):
16891689
return index_col_val
16901690

16911691
def edit_cell(self, index, column, value):
1692+
"""
1693+
Edit a cell of the grid, given the index and column of the cell
1694+
to edit, as well as the new value of the cell. Results in a
1695+
``cell_edited`` event being fired.
1696+
1697+
Parameters
1698+
----------
1699+
index : object
1700+
The index of the row containing the cell that is to be edited.
1701+
column : str
1702+
The name of the column containing the cell that is to be edited.
1703+
value : object
1704+
The new value for the cell.
1705+
"""
16921706
old_value = self._df.loc[index, column]
16931707
self._df.loc[index, column] = value
16941708
self._unfiltered_df.loc[index, column] = value

0 commit comments

Comments
 (0)