slick grid clone, for mobile,desktop devices
** Sort performance is not fast as javascript version
Grid Options have it's own class instead of Map object, Can be ignore on construction
var opt = new GridOptions()
..explicitInitialization= false
..multiColumnSort= false;
var grid = new SlickGrid.fromOpt(el,data,[],opt);
Formatter adopt TFormatter function interface.
typedef TFormatter = String Function(
int row, int cell, dynamic value, Column columnDef, Map dataContext);
Specify formatter in inital columns will auto collect formatter to GridOption's [FormatterFactory], if dynamic swap column, and need special formatter Function, using GridOption's [FormatterFactory],
limitation: visible row: when calculate numVisibleRows, when we apply dynamic row height, minimal dynamic row height must >= single row hight Current design
Initial support customer element, see example: custom-elem.dart
Compatible with angular 1/2 dart
import 'slick_custom.dart'
registerElem();
<cj-grid>
<style>
.special-style-here {..}
</style>
</cj-grid>
Use FilteredList.class in slick_util.dart to wrap data Example: ColumnFilter.dart
Not to mix with checkbox select column Example: headerRow.dart
No shadow dom Example: gdoc-header.dart
//add menu
column.header = {'menu': {
'items': [
{
'iconImage': "../images/sort-asc.gif",
'title': "Sort Ascending",
'command': "sort-asc"
}]
}};
HeaderMenu headerMenuPlugin=new HeaderMenu({});
headerMenuPlugin.onBeforeMenuShow.subscribe((e, args) {
List<MenuItem> menuList = args['menu'];
});
headerMenuPlugin.onCommand.subscribe((e, args) {
if(args['command']=='hide'){
if(columnList.remove(args['column'])){
tmpCol.add(args['column']);
};
args['grid'].setColumns(columnList);
}
});
grid.registerPlugin(headerMenuPlugin);
<link rel="stylesheet" href="https://github.com/cjkao/slickdart/blob/master/packages/slickdart/css/plugins-common.css" type="text/css" />
<link rel="stylesheet" href="https://github.com/cjkao/slickdart/blob/master/packages/slickdart/css/plugins-gdoc-style.css" type="text/css" />
<link rel="stylesheet" href="https://github.com/cjkao/slickdart/blob/master/packages/slickdart/css/slick.headermenu.css" type="text/css" />
Right click on grid that show download or copy option, Example: angular/popup.dart, custom-elem.dart
Follow steps:
<script src="https://github.com/cjkao/slickdart/raw/master/packages/slickdart/plugin/copy/ZeroClipboard.min.js"></script>
<cj-grid download='f.csv'></cj-grid>
Example: Bs3_tree.dart
Support one selection area only, can not cross frozen area
grid.SlickGrid sg = new grid.SlickGrid.fromOpt(el, data, column, opt);
var cellSelectModel = new CellSelectionModel();
cellSelectModel.onSelectedRangesChanged.subscribe((var e, args) {
cellSelectModel.getSelectedRanges().forEach(print);
});
sg.setSelectionModel(cellSelectModel);
grid.setSelectedRows([rowIndex1,rowIndex2...etc]);
grid.invalidate();
Cell editor need to extend Editor
class, refer to slick_editor.dart file
getEditorLock().commitCurrentEdit()
// or
commitCurrentEdit();
// or
commitEditAndSetFocus();
cancelEditAndSetFocus();
* Enable text selection
```dart
new GridOptions()..enableTextSelectionOnCells=true;
Editor Flow
loadValue()
, serialize()
value (for value change event)isValueChanged()
-> false -> make cell back to normal. if isValueChanged()==true
, call validate()
validate()==false
, add invalid
class to cellvalidate()=true
, generate Edit Command object and call serialize()
, if GridOption provide editCommandHandler, call handler, else call applyValue()
to update data rowDropdown list Editor Drop down list editor within cell using standard input-select element, see SelectListEditor. Constructor accept a map with format as {value: display_name,...}
sample code:
//enable editable in GridOption
new grid.GridOptions()..editable = true
//set editor for column
new Column()
..field = "City"
// NY is value, "New York" is display name on the Select Option
..editor = new SelectListEditor({"NY": "New York", "TPE": "Taipei"})
..formatter =(int row, int cell, value, Column columnDef, Map dataContext)
{ return value=="NY" ? "NEW YORK" : "TAIPEI";}
}
Sample code:
new grid.Column.fromMap(
{'field': "...", 'editor': new CheckboxEditor(), 'formatter': CheckmarkFormatter}),
cssClass
in Column
definition.nopad{
padding-left: 0px;
padding-right: 0px;
}
new grid.Column.fromMap(
{'field': "title", 'formatter': SplitFormatter})
..cssClass = 'nopad';
_height
to specify row heightSplitFormatter(int row, int cell, int value, grid.Column columnDef, Map dataRow) {
if (dataRow['_height'] != null && dataRow['_height'] > 90) {
return '''
<div class="h40">
bbbbbbb $value
<span>$cell<span class='important'> $row
</div>
<hr/>
<div>
aaa
</div>
''';
} else {
return value;
}
}
Add style to upper row
.h40 {
height: 40px;
display: block;
background: yellow;
word-wrap: break-word;
white-space: normal;
}