Telerik MVC Grid - 排序停止 javascript
我在 MVC3 中有一个使用 Telerik 网格的页面。在网格中,每一行都有一个文本框,我在其中输入小数。我有一个 css 类“HoursNew”,用于连接 jQuery 插件 ( autoNumeric.js )。我还有一个 onBlur 函数,可以将任何小数输入四舍五入到最接近的半个小数。 问题是,对列进行排序后,所有 JavaScript 似乎都停止工作。 autoNumeric.js 停止与我触发 onBlur 的函数一起工作。
$(document).ready(function () {
$('.HoursNew').autoNumeric({ pSign: 's', vMin: '-999.5', vMax: '999.5', mRound: 'C', aPad: false });
$('.HoursNew').blur(function () { roundToHalf(this); });
});
// Round decimal to nearest .5
// v is input object
function roundToHalf(v) {
var value = v.value;
var r;
//alert(v.id);
var converted = parseFloat(value); // Make sure we have a number
var decimal = (converted - parseInt(converted, 10)); // Pull the decimal value
decimal = Math.round(decimal * 10);
if (decimal == 5) { return (parseInt(converted, 10) + 0.5); } // leave alone if .5
if ((decimal < 3) || (decimal > 7)) {
r = Math.round(converted); // Round up or down to nearest whole number
} else {
r = (parseInt(converted, 10) + 0.5); //round to .5
}
//alert(r);
// reset input value to new value
$('#' + v.id).val(r);
}
页面在第一次加载时工作正常,只是在排序后出现这个问题。有什么建议吗?
I have a page in MVC3 using a Telerik grid. In the grid, for each row, is a textbox that I'm entering an decimal. I have a css class, 'HoursNew', which is used to connect a jQuery plugin ( autoNumeric.js ). I also have an onBlur function to round any decimal input to the nearest half decimal.
Problem is, after sorting a column, all JavaScript seems to stop working. The autoNumeric.js stops working along with the function I have that fires onBlur.
$(document).ready(function () {
$('.HoursNew').autoNumeric({ pSign: 's', vMin: '-999.5', vMax: '999.5', mRound: 'C', aPad: false });
$('.HoursNew').blur(function () { roundToHalf(this); });
});
// Round decimal to nearest .5
// v is input object
function roundToHalf(v) {
var value = v.value;
var r;
//alert(v.id);
var converted = parseFloat(value); // Make sure we have a number
var decimal = (converted - parseInt(converted, 10)); // Pull the decimal value
decimal = Math.round(decimal * 10);
if (decimal == 5) { return (parseInt(converted, 10) + 0.5); } // leave alone if .5
if ((decimal < 3) || (decimal > 7)) {
r = Math.round(converted); // Round up or down to nearest whole number
} else {
r = (parseInt(converted, 10) + 0.5); //round to .5
}
//alert(r);
// reset input value to new value
$('#' + v.id).val(r);
}
Page works fine on first load, just this problem after a sort. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有预感,排序时,网格会进行 ajax 调用来渲染新的网格。这意味着您在
$(document).ready
中执行的任何绑定都将被删除。请查看 Telerik 文档中有关客户端事件的页面。您需要将此部分添加到网格定义中:
并且要重新绑定此 javascript:
I have a hunch that when sorting, the grid is making an ajax call that renders a new grid. What this means is that any bindings you performed in
$(document).ready
are removed.Take a look at this page on client-side events in the Telerik documentation. You'll need to add this section to your grid definition:
And this javascript to rebind: