this.slick_options = {
enableCellNavigation: false,
enableColumnReorder: true,
+ showHeaderRow: true,
+ syncColumnCellResize: true,
};
- this.slick_data=[];
+ this.slick_data = [];
+ this.slick_dataview = new Slick.Data.DataView();
+ var self=this;
+ this.slick_dataview.onRowCountChanged.subscribe ( function (e,args) {
+ self.slick_grid.updateRowCount();
+ self.slick_grid.autosizeColumns();
+ self.slick_grid.render();
+ });
var selector="#grid-"+this.options.domid;
if (debug_deep) {
cssClass: "slick-cell-checkboxsel"
});
this.slick_columns.push(checkbox_selector.getColumnDefinition());
- this.slick_grid = new Slick.Grid(selector, this.slick_data, this.slick_columns, this.slick_options);
+ this.slick_grid = new Slick.Grid(selector, this.slick_dataview, this.slick_columns, this.slick_options);
this.slick_grid.setSelectionModel (new Slick.RowSelectionModel ({selectActiveRow: false}));
this.slick_grid.registerPlugin (checkbox_selector);
// autotooltips: for showing the full column name when ellipsed
this.columnpicker = new Slick.Controls.ColumnPicker (this.slick_columns, this.slick_grid, this.slick_options)
- }, // initialize_table
- // Determine index of key in the table columns
- getColIndex: function(key, cols) {
- var tabIndex = $.map(cols, function(x, i) { if (x.sTitle == key) return i; });
- return (tabIndex.length > 0) ? tabIndex[0] : -1;
- }, // getColIndex
-
- checkbox_html : function (key, value) {
- if (debug_deep) messages.debug("checkbox_html, value="+value);
- var result="";
- // Prefix id with plugin_uuid
- result += "<input";
- result += " class='querytable-checkbox'";
- result += " id='" + this.flat_id(this.id('checkbox', value)) + "'";
- result += " name='" + key + "'";
- result += " type='checkbox'";
- result += " autocomplete='off'";
- if (value === undefined) {
- messages.warning("querytable.checkbox_html - undefined value");
- } else {
- result += " value='" + value + "'";
- }
- result += "></input>";
- return result;
- },
+ }, // initialize_table
new_record: function(record) {
this.slick_data.push(record);
},
clear_table: function() {
- console.log("clear_table not implemented");
+ this.slick_data=[];
+ this.slick_dataview.setItems(this.slick_data,this.key);
},
redraw_table: function() {
- this.table.fnDraw();
+ this.slick_grid.autosizeColumns();
+ this.slick_grid.render();
},
show_column: function(field) {
- var oSettings = this.table.fnSettings();
- var cols = oSettings.aoColumns;
- var index = this.getColIndex(field,cols);
- if (index != -1)
- this.table.fnSetColumnVis(index, true);
+ console.log ("querytable.show_column not yet implemented with slickgrid - field="+field);
},
hide_column: function(field) {
- console.log("hide_column not implemented - field="+field);
+ console.log("querytable.hide_column not implemented with slickgrid - field="+field);
},
set_checkbox: function(record, checked) {
- console.log("set_checkbox not yet implemented with slickgrid");
- return;
/* Default: checked = true */
if (checked === undefined) checked = true;
messages.warning("querytable.set_checkbox record has no id to figure which line to tick");
return;
}
- var checkbox_id = this.flat_id(this.id('checkbox', id));
- // function escape_id(myid) is defined in portal/static/js/common.functions.js
- checkbox_id = escape_id(checkbox_id);
- // using dataTables's $ to search also in nodes that are not currently displayed
- var element = this.table.$(checkbox_id);
- if (debug_deep)
- messages.debug("set_checkbox checked=" + checked
- + " id=" + checkbox_id + " matches=" + element.length);
- element.attr('checked', checked);
+ var index = this.slick_dataview.getIdxById(id);
+ var selectedRows=this.slick_grid.getSelectedRows();
+ if (checked) // add index in current list
+ selectedRows=selectedRows.concat(index);
+ else
+ selectedRows=selectedRows.filter(function(idx) {return idx!=index;});
+ this.slick_grid.setSelectedRows(selectedRows);
},
/*************************** QUERY HANDLER ****************************/
on_all_query_done: function() {
if (debug) messages.debug("1-shot initializing dataTables content with " + this.slick_data.length + " lines");
var start=new Date();
- this.slick_grid.setData (this.slick_data, true);
- this.slick_grid.autosizeColumns();
- this.slick_grid.render();
+ // use this.key as the key for identifying rows
+ this.slick_dataview.setItems (this.slick_data, this.key);
var duration=new Date()-start;
- if (debug) messages.debug("setData+render took " + duration + " ms");
+ if (debug) messages.debug("setItems " + duration + " ms");
if (debug_deep) {
// show full contents of first row app
for (k in this.slick_data[0]) messages.debug("slick_data[0]["+k+"]="+this.slick_data[0][k]);