Created
August 5, 2013 10:29
-
-
Save jcsjcs/6154932 to your computer and use it in GitHub Desktop.
Copy of SlickGrid checkbox example displaying loss of selection on filter.
Select a few rows. Press the button to log selection. Filter rows. Press button. Select more rows and press button. Unfilter. press button.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> | |
<link rel="stylesheet" href="../slick.grid.css" type="text/css"/> | |
<link rel="stylesheet" href="../css/smoothness/jquery-ui-1.8.16.custom.css" type="text/css"/> | |
<link rel="stylesheet" href="examples.css" type="text/css"/> | |
<link rel="stylesheet" href="../controls/slick.columnpicker.css" type="text/css"/> | |
<style> | |
.slick-cell-checkboxsel { | |
background: #f0f0f0; | |
border-right-color: silver; | |
border-right-style: solid; | |
} | |
</style> | |
</head> | |
<body> | |
<div style="position:relative"> | |
<div style="width:600px;"> | |
<div id="myGrid" style="width:100%;height:500px;"></div> | |
</div> | |
<div class="options-panel"> | |
<h2>Demonstrates:</h2> | |
<ul> | |
<li>Checkbox row select column</li> | |
<li><label>And col A including:</label> | |
<input type=text id="txtSearch" style="width:100px;"></li> | |
</ul> | |
<button id="btnSelected">Log the currently selected ids</button> | |
<h3>Log of selected ids</h3> | |
<p id="log"></p> | |
</div> | |
</div> | |
<script src="../lib/firebugx.js"></script> | |
<script src="../lib/jquery-1.7.min.js"></script> | |
<script src="../lib/jquery-ui-1.8.16.custom.min.js"></script> | |
<script src="../lib/jquery.event.drag-2.2.js"></script> | |
<script src="../slick.core.js"></script> | |
<script src="../plugins/slick.checkboxselectcolumn.js"></script> | |
<script src="../plugins/slick.autotooltips.js"></script> | |
<script src="../plugins/slick.cellrangedecorator.js"></script> | |
<script src="../plugins/slick.cellrangeselector.js"></script> | |
<script src="../plugins/slick.cellcopymanager.js"></script> | |
<script src="../plugins/slick.cellselectionmodel.js"></script> | |
<script src="../plugins/slick.rowselectionmodel.js"></script> | |
<script src="../slick.dataview.js"></script> | |
<script src="../controls/slick.columnpicker.js"></script> | |
<script src="../slick.formatters.js"></script> | |
<script src="../slick.editors.js"></script> | |
<script src="../slick.grid.js"></script> | |
<script> | |
var grid; | |
var data = []; | |
var options = { | |
editable: true, | |
enableCellNavigation: true, | |
asyncEditorLoading: false, | |
autoEdit: false | |
}; | |
var columns = []; | |
var searchString = ""; | |
function myFilter(item) { | |
if (searchString != "" && item[0].indexOf(searchString) == -1) { | |
return false; | |
} | |
return true; | |
} | |
$(function () { | |
for (var i = 0; i < 100; i++) { | |
var d = (data[i] = {}); | |
d['id'] = i + 1; | |
d[0] = "Row " + i; | |
} | |
var checkboxSelector = new Slick.CheckboxSelectColumn({ | |
cssClass: "slick-cell-checkboxsel" | |
}); | |
columns.push(checkboxSelector.getColumnDefinition()); | |
columns.push({id: 'id', name: 'id', field: 'id'}); | |
for (var i = 0; i < 5; i++) { | |
columns.push({ | |
id: i, | |
name: String.fromCharCode("A".charCodeAt(0) + i), | |
field: i, | |
width: 100, | |
editor: Slick.Editors.Text | |
}); | |
} | |
// initialize the model | |
dataView = new Slick.Data.DataView({ inlineFilters: true }); | |
dataView.beginUpdate(); | |
dataView.setItems(data); | |
dataView.setFilter(myFilter); | |
dataView.endUpdate(); | |
grid = new Slick.Grid("#myGrid", dataView, columns, options); | |
grid.setSelectionModel(new Slick.RowSelectionModel({selectActiveRow: false})); | |
grid.registerPlugin(checkboxSelector); | |
dataView.syncGridSelection(grid, true); | |
// wire up model events to drive the grid | |
dataView.onRowCountChanged.subscribe(function (e, args) { | |
grid.updateRowCount(); | |
grid.render(); | |
}); | |
dataView.onRowsChanged.subscribe(function (e, args) { | |
grid.invalidateRows(args.rows); | |
grid.render(); | |
}); | |
var columnpicker = new Slick.Controls.ColumnPicker(columns, grid, options); | |
// Which rows are currently selected. | |
$("#btnSelected").click(function () { | |
var sel = grid.getSelectedRows(); | |
if (sel.length === 0) { | |
$('<span>Nothing selected.</span><hr>').appendTo('#log'); | |
} | |
else { | |
var ids = $.map(sel, function(e,i) {return grid.getDataItem(e).id; }); | |
$('<span>Selected ids: '+ids.join(', ')+'</span><hr>').appendTo('#log'); | |
} | |
}); | |
// wire up the search textbox to apply the filter to the model | |
$("#txtSearch").keyup(function (e) { | |
// clear on Esc | |
if (e.which == 27) { | |
this.value = ""; | |
} | |
searchString = this.value; | |
dataView.refresh(); | |
}); | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment