Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A functional AJAX Data Store Example now using HackerNews instead of Digg #412

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.DS_Store
.gitk*
.idea/*
.idea/*
examples/.idea/*
23 changes: 0 additions & 23 deletions build/minimize.bat

This file was deleted.

172 changes: 0 additions & 172 deletions build/minimize.cs

This file was deleted.

58 changes: 32 additions & 26 deletions examples/example6-ajax-loading.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<body>
<div style="width:700px;float:left;">
<div class="grid-header" style="width:100%">
<label>Digg stories</label>
<label>Hackernews stories</label>
<span style="float:right;display:inline-block;">
Search:
<input type="text" id="txtSearch" value="apple">
Expand All @@ -55,8 +55,7 @@ <h2>Demonstrates:</h2>

<h2>WARNING:</h2>
<ul>
<li>Digg API uses request rate limiting. You may occasionally get an error if you do a frequent
scrolling/resorting/searching.
<li>API access to Hackernews provided through ThriftDB has some latency when paging through results. Be patient.
</li>
</ul>
</div>
Expand All @@ -77,15 +76,20 @@ <h2>WARNING:</h2>
var loader = new Slick.Data.RemoteModel();

var storyTitleFormatter = function (row, cell, value, columnDef, dataContext) {
return "<b><a href='" + dataContext["link"] + "' target=_blank>" +
dataContext["title"] + "</a></b><br/>" + dataContext["description"];
s ="<b><a href='" + dataContext["url"] + "' target=_blank>" +
dataContext["title"] + "</a></b><br/>";
desc = dataContext["text"];
if (desc) { // on Hackernews many stories don't have a description
s += desc;
}
return s;
};


var columns = [
{id: "num", name: "#", field: "index", width: 40},
{id: "story", name: "Story", width: 580, formatter: storyTitleFormatter, cssClass: "cell-story"},
{id: "diggs", name: "Diggs", field: "diggs", width: 60, sortable: true}
{id: "points", name: "Points", field: "points", width: 60}
];

var options = {
Expand All @@ -95,9 +99,6 @@ <h2>WARNING:</h2>
enableCellNavigation: false
};

var loadingIndicator = null;


$(function () {
grid = new Slick.Grid("#myGrid", loader.data, columns, options);

Expand All @@ -106,39 +107,44 @@ <h2>WARNING:</h2>
loader.ensureData(vp.top, vp.bottom);
});

grid.onSort.subscribe(function (e, args) {
loader.setSort(args.sortCol.field, args.sortAsc ? 1 : -1);
var vp = grid.getViewport();
loader.ensureData(vp.top, vp.bottom);
});

loader.onDataLoading.subscribe(function () {
if (!loadingIndicator) {
loadingIndicator = $("<span class='loading-indicator'><label>Buffering...</label></span>").appendTo(document.body);
var $g = $("#myGrid");
indicators = new Array();

loadingIndicator
.css("position", "absolute")
.css("top", $g.position().top + $g.height() / 2 - loadingIndicator.height() / 2)
.css("left", $g.position().left + $g.width() / 2 - loadingIndicator.width() / 2);
}
loader.onDataLoading.subscribe(function (e, args) {
if(indicators.length == 0) {
loadingIndicator = $("<span class='loading-indicator'><label>Buffering...</label></span>").appendTo(document.body);
var $g = $("#myGrid");

loadingIndicator
.css("position", "absolute")
.css("top", $g.position().top + $g.height() / 2 - loadingIndicator.height() / 2)
.css("left", $g.position().left + $g.width() / 2 - loadingIndicator.width() / 2);

loadingIndicator.show();
loadingIndicator.show();
indicators.push(loadingIndicator);
}
else
indicators.push(null);
});

loader.onDataLoaded.subscribe(function (e, args) {
for (var i = args.from; i <= args.to; i++) {
for (var i = args.from; i < args.to; i++) {
grid.invalidateRow(i);
}

grid.updateRowCount();
grid.render();

loadingIndicator.fadeOut();
i = indicators.pop();
if(i != null)
i.fadeOut();
});

$("#txtSearch").keyup(function (e) {
if (e.which == 13) {
loader.clear();
grid.updateRowCount();
grid.render();
loader.setSearch($(this).val());
var vp = grid.getViewport();
loader.ensureData(vp.top, vp.bottom);
Expand Down
9 changes: 9 additions & 0 deletions examples/example9-row-reordering.html
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,21 @@
$.drop({mode: "mouse"});
$("#dropzone")
.bind("dropstart", function (e, dd) {
if (dd.mode != "recycle") {
return;
}
$(this).css("background", "yellow");
})
.bind("dropend", function (e, dd) {
if (dd.mode != "recycle") {
return;
}
$(dd.available).css("background", "pink");
})
.bind("drop", function (e, dd) {
if (dd.mode != "recycle") {
return;
}
var rowsToDelete = dd.rows.sort().reverse();
for (var i = 0; i < rowsToDelete.length; i++) {
data.splice(rowsToDelete[i], 1);
Expand Down
4 changes: 2 additions & 2 deletions slick.editors.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,10 @@
scope.cancel();
} else if (e.which == $.ui.keyCode.TAB && e.shiftKey) {
e.preventDefault();
grid.navigatePrev();
args.grid.navigatePrev();
} else if (e.which == $.ui.keyCode.TAB) {
e.preventDefault();
grid.navigateNext();
args.grid.navigateNext();
}
};

Expand Down
Loading