Hello all. First of all, great work on this project. I am trying to use it to do an ajax load in
asp.net to a dataviewer. My base was example
#4 and
#15. Pretty much, i'm trying to do the following. I highlighted how I'm trying to accomplish this below, along with the corresponding JSON, which looks to be in good form? Any thoughts?
<script type="text/javascript">
var dataView;
var grid;
var mydata = [];
var columns = [
{ name: 'Date', field: 'date', sortable: true, minWidth: 90 },
{ name: 'File Name', field: 'filename', filter: 'text', sortable: true, minWidth: 100 },
{ name: 'Description', field: 'description', filter: 'text', sortable: true, width: 62 },
{ name: 'Uploaded by', field: 'contactname', filter: 'text', sortable: true, width: 62 }
];
var options = {
enableCellNavigation: true,
forceFitColumns: true,
topPanelHeight: 25
};
var sortcol = "filename";
var sortdir = 1;
var searchString = "";
function myFilter(item, args) {
var myfilename = item["filename"].toUpperCase();
var myDescription = item["Description"].toUpperCase();
var mySearch = args.searchString.toUpperCase();
if (mySearch != "" && myfilename.indexOf(mySearch) == -1 && myDescription.indexOf(mySearch) == -1) {
return false;
}
return true;
}
function comparer(a, b) {
var x = a[sortcol], y = b[sortcol];
return (x == y ? 0 : (x > y ? 1 : -1));
}
$(".grid-header .ui-icon")
.addClass("ui-state-default ui-corner-all")
.mouseover(function (e) {
$(e.target).addClass("ui-state-hover")
})
.mouseout(function (e) {
$(e.target).removeClass("ui-state-hover")
});
//hide the modal on startup
$(document).ready(function () {
dataView = new Slick.Data.DataView({ inlineFilters: true });
dataView.setPagingOptions({pageSize: 50});
grid = new Slick.Grid("#myGrid", dataView, columns, options);
grid.setSelectionModel(new Slick.RowSelectionModel());
//right click
grid.onContextMenu.subscribe(function (e) {
});
//left click
grid.onClick.subscribe(function (e) {
});
var pager = new Slick.Controls.Pager(dataView, grid, $("#pager"));
var columnpicker = new Slick.Controls.ColumnPicker(columns, grid, options);
grid.onSort.subscribe(function (e, args) {
sortdir = args.sortAsc ? 1 : -1;
sortcol = args.sortCol.field;
if ($.browser.msie && $.browser.version <= 8) {
dataView.fastSort(sortcol, args.sortAsc);
} else {
dataView.sort(comparer, args.sortAsc);
}
});
dataView.onRowsChanged.subscribe(function (e, args) {
grid.invalidateRows(args.rows);
grid.render();
});
var h_runfilters = null;
// wire up the search textbox to apply the filter to the model
$("#txtSearch").keyup(function (e) {
//on enter search
if (e.which == 13) {
searchString = this.value;
updateFilter();
}
});
function updateFilter() {
dataView.setFilterArgs({
searchString: searchString
});
dataView.refresh();
}
// initialize the model after all the events have been hooked up
dataView.beginUpdate();
// get the data
$.getJSON('PostBack.aspx?ID=1', function(data) { dataView.setItems(data); }); dataView.setFilterArgs({
searchString: searchString
});
dataView.setFilter(myFilter);
dataView.endUpdate();
// if you don't want the items that are not visible (due to being filtered out
// or being on a different page) to stay selected, pass 'false' to the second arg
dataView.syncGridSelection(grid, true);
});
</script>
The JSON looks like so:
{
"data": [
{
"id": 40,
"filename": "Lease_50_Detail_Workbook.xls",
"contactname": "Jeff Mullen",
"date": "5/25/2012 1:59:50 PM",
"description": "Attachment"
},
{
"id": 41,
"filename": "Lease_53_Detail_Workbook.xls",
"contactname": "Jeff Mullen",
"date": "5/25/2012 2:00:32 PM",
"description": "Attachment"
}
]
}