Skip to content

Commit

Permalink
Merge pull request #211 from quantopian/edit-cell-docs
Browse files Browse the repository at this point in the history
Add doc string for the edit_cell method
  • Loading branch information
TimShawver committed Jul 11, 2018
2 parents f0d9dfe + 050fc01 commit 7612e2c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 15 deletions.
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qgrid",
"version": "1.1.0",
"version": "1.1.1",
"description": "An Interactive Grid for Sorting and Filtering DataFrames in Jupyter Notebook",
"author": "Quantopian Inc.",
"main": "src/index.js",
Expand Down
8 changes: 8 additions & 0 deletions js/src/qgrid.css
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@
height: 315px !important;
}

.q-grid-toolbar {
display: none;
}

.show-toolbar .q-grid-toolbar {
display: block;
}

.output_scroll .show-toolbar .q-grid {
height: 284px !important;
}
Expand Down
33 changes: 23 additions & 10 deletions js/src/qgrid.widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class QgridModel extends widgets.DOMWidgetModel {
_view_name : 'QgridView',
_model_module : 'qgrid',
_view_module : 'qgrid',
_model_module_version : '^1.1.0',
_view_module_version : '^1.1.0',
_model_module_version : '^1.1.1',
_view_module_version : '^1.1.1',
_df_json: '',
_columns: {}
});
Expand All @@ -62,16 +62,21 @@ class QgridView extends widgets.DOMWidgetView {
if (!this.$el.hasClass('q-grid-container')){
this.$el.addClass('q-grid-container');
}

if (this.model.get('show_toolbar')) {
this.initialize_toolbar();
}

this.initialize_toolbar();
this.initialize_slick_grid();
}

initialize_toolbar() {
this.$el.addClass('show-toolbar');
if (!this.model.get('show_toolbar')){
this.$el.removeClass('show-toolbar');
} else {
this.$el.addClass('show-toolbar');
}

if (this.toolbar){
return;
}

this.toolbar = $("<div class='q-grid-toolbar'>").appendTo(this.$el);

let append_btn = (btn_info) => {
Expand Down Expand Up @@ -196,7 +201,10 @@ class QgridView extends widgets.DOMWidgetView {
* type of data in the columns of the DataFrame provided by the user.
*/
initialize_slick_grid() {
this.grid_elem = $("<div class='q-grid'>").appendTo(this.$el);

if (!this.grid_elem) {
this.grid_elem = $("<div class='q-grid'>").appendTo(this.$el);
}

// create the table
var df_json = JSON.parse(this.model.get('_df_json'));
Expand Down Expand Up @@ -391,6 +399,7 @@ class QgridView extends widgets.DOMWidgetView {
this.columns,
this.grid_options
);
this.grid_elem.data('slickgrid', this.slick_grid);

if (this.grid_options.forceFitColumns){
this.grid_elem.addClass('force-fit-columns');
Expand All @@ -414,6 +423,8 @@ class QgridView extends widgets.DOMWidgetView {
this.slick_grid.setSelectionModel(new Slick.RowSelectionModel());
this.slick_grid.setCellCssStyles("grouping", this.row_styles);
this.slick_grid.render();

this.update_size();

var render_header_cell = (e, args) => {
var cur_filter = this.filters[args.column.id];
Expand Down Expand Up @@ -664,7 +675,7 @@ class QgridView extends widgets.DOMWidgetView {
*/
handle_msg(msg) {
if (msg.type === 'draw_table') {
this.initialize_qgrid();
this.initialize_slick_grid();
} else if (msg.type == 'show_error') {
alert(msg.error_msg);
if (msg.triggered_by == 'add_row' ||
Expand Down Expand Up @@ -773,6 +784,8 @@ class QgridView extends widgets.DOMWidgetView {
this.slick_grid.scrollRowIntoView(msg.rows[0]);
}
this.ignore_selection_changed = false;
} else if (msg.type == 'change_show_toolbar') {
this.initialize_toolbar();
} else if (msg.col_info) {
var filter = this.filters[msg.col_info.name];
filter.handle_msg(msg);
Expand Down
2 changes: 1 addition & 1 deletion qgrid/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version_info = (1, 1, 0, 'final')
version_info = (1, 1, 1, 'final')

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

Expand Down
20 changes: 17 additions & 3 deletions qgrid/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,8 @@ class can be constructed directly but that's not recommended because
_model_name = Unicode('QgridModel').tag(sync=True)
_view_module = Unicode('qgrid').tag(sync=True)
_model_module = Unicode('qgrid').tag(sync=True)
_view_module_version = Unicode('1.1.0').tag(sync=True)
_model_module_version = Unicode('1.1.0').tag(sync=True)
_view_module_version = Unicode('1.1.1').tag(sync=True)
_model_module_version = Unicode('1.1.1').tag(sync=True)

_df = Instance(pd.DataFrame)
_df_json = Unicode('', sync=True)
Expand Down Expand Up @@ -843,7 +843,7 @@ def _grid_options_changed(self):
def _show_toolbar_changed(self):
if not self._initialized:
return
self._rebuild_widget()
self.send({'type': 'change_show_toolbar'})

def _update_table(self,
update_columns=False,
Expand Down Expand Up @@ -1689,6 +1689,20 @@ def _add_row(self, row):
return index_col_val

def edit_cell(self, index, column, value):
"""
Edit a cell of the grid, given the index and column of the cell
to edit, as well as the new value of the cell. Results in a
``cell_edited`` event being fired.
Parameters
----------
index : object
The index of the row containing the cell that is to be edited.
column : str
The name of the column containing the cell that is to be edited.
value : object
The new value for the cell.
"""
old_value = self._df.loc[index, column]
self._df.loc[index, column] = value
self._unfiltered_df.loc[index, column] = value
Expand Down

0 comments on commit 7612e2c

Please sign in to comment.