我構建了一個智能數據網格,其中包含將識別(模糊)它們是否發生更改以及值是否升高或降低的單元格。我的jQuery似乎沒有與Wijmo Grid一起工作
下面是它的樣子。當用戶懸停一個已更改的框並顯示頁面第一次加載時的值時,會出現灰色的工具提示。
我想將其轉換爲一個Wijmo電網,但保持相同的上/下的腳本,以顯示何時以及如何值的變化。但是,當我將表格初始化爲Wijmo網格時,突然我的腳本在所有瀏覽器中停止工作。
問題:爲什麼會發生這種情況,是否有簡單的解決方法?你能不能用傳統的jQuery和Javascript訪問Wijmo單元格?
部分HTML代碼(Full code and working example without Widjmo here):
<table id="data-grid">
<thead>
<tr>
<th>March</th>
<th>April</th>
<th>May</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" value="12000" /></td>
<td><input type="text" value="1000" /></td>
<td><input type="text" value="100000" /></td>
</tr>
這裏是我當前的jQuery代碼(Full code and working example without Widjmo here):
$(function() {
// Initializes data grid as a Widjmo Grid (currently commented out)
//$("#data-grid").wijgrid();
// Array to store the initial values in grid
var initialValues = [];
// Assigns an index ID to each cell in the grid
$('input').each(function(index) {
initialValues[index] = $(this).val();
$(this).data('id', index);
});
// Checks cell(s) for changes on blur (lose focus)
$("input").blur(function() {
var $t = parseInt($(this).val(), 10);
var $s = parseInt(initialValues[$(this).data('id')], 10);
// Value has changed
if($t != $s) {
var sign = "";
if($t-$s > 0) {
sign="+";
}
$(this).parent().children(".tooltip").remove();
$(this).parent().append("<div class='tooltip'>Initial " + $s + "<br/>Change " + sign + ($t-$s) + "</div>");
}
// Value is no different from intial value
if($t == $s) {
$(this).removeClass("up down");
$(this).parent().children(".tooltip").remove();
$(this).parent().children(".up-indicator, .down-indicator").remove();
}
// Value is greater than initial
else if($t > $s) {
$(this).removeClass("up down");
$(this).parent().children(".up-indicator, .down-indicator").remove();
$(this).addClass("up");
$(this).parent().append("<div class='up-indicator'></div>");
}
// Value is less than initial
else if($t < $s) {
$(this).removeClass("up down");
$(this).parent().children(".up-indicator, .down-indicator").remove();
$(this).addClass("down");
$(this).parent().append("<div class='down-indicator'></div>");
}
// Conpute the net change
netChange(initialValues);
});
// Displays tooltip of changed items
$("input").hover(function() {
$(this).parent().children(".tooltip").toggle();
});
// Computes the net change in the data grid
function netChange(initialValues) {
var runningTotal = 0;
$('input').each(function() {
runningTotal += parseInt($(this).val(), 10);
});
var intialTotal = 0;
for (var i = 0; i < initialValues.length; i++) {
intialTotal += parseInt(initialValues[i], 10);
}
var changes = $(".up, .down").length;
$("#items").text(changes + " Items");
$("#net").text("Net: " + (runningTotal - intialTotal));
}
});
您使用的瀏覽器是? – Dom 2013-03-12 18:40:25
Chrome版本25.0 [.1364.152] – Jon 2013-03-12 18:46:38