我在我的页面中添加了一个jqGrid表,在这里我需要添加寄存器,在我做了一些处理后,我需要重新加载de数据,所有的都是本地的,没有服务器通信,这是我的代码。
$(function () {
$.extend(true, $.jgrid.inlineEdit, {
beforeCancelRow: function (options, rowid) {
$(this).jqGrid('saveRow', rowid);
$(this).setCell(rowid, 'TipoEtiqueta', '', '', { 'title': null });
return false;
}
});
L_Grid.jqGrid({
loadonce: false,
data: notas,
datatype: "local",
refresh: true,
colNames: ['Código Etiqueta', 'Tiempo (hh:mm:ss)', 'Descripción', 'Privada', 'Eliminar'],
colModel: [
{
name: 'Codigo', index: 'Codigo', hidden: true, search: false
},
{
name: 'TiempoMilisegundos', index: 'TiempoMilisegundos', align: "center", search: false,
formatter: function (cellvalue, options, rowObject) {
return TimeFormat(cellvalue)
},
cellattr: function (rowId, val) {
return 'aria-label="Tiempo de la etiqueta ' + TimeFormat(val) + '" title="Tiempo de la etiqueta" onclick="navegarEtiqueta(' + val + ')" tabindex="0"';
}
},
{
name: 'Descripcion', index: 'Descripcion', align: "center", width: 320, editable: true, editoptions: { required: false, maxlength: 255, "class": "descripcion-etiqueta", list: "etiquetasPredefinidas" }, classes: "descripcion-etiqueta",
cellattr: function (rowId, val) {
return 'tabindex="0"';
}
},
{
name: 'TipoEtiqueta', index: 'TipoEtiqueta', align: "center", search: false, editable: true,
formatter: function (cellvalue, options, rowObject) {
var titulo = cellvalue ? "Privada": "Pública";
return ' <label class="switch" title="' + titulo +'">'
+ ' <input tabindex="0" type="checkbox" ' + ValidarCheck(cellvalue) + ' aria-disabled="true" disabled aria-label="Indicador de etiqueta privada" role="switch">'
+ ' <span class="slider round" tabindex="0" aria-label="Indicador de etiqueta privada ' + TipoEtiqueta(cellvalue) + '"></span>'
+ ' </label>';
},
edittype: 'custom',
editoptions: {
custom_element: function (value, options) {
var V_Localdata = L_Grid.jqGrid('getGridParam', 'data');
var V_RowData = V_Localdata[L_Grid.jqGrid('getGridParam', '_index')[options.rowId]];
return $('<label class="switch">'
+ ' <input tabindex="0" type="checkbox" ' + ValidarCheck(V_RowData.TipoEtiqueta) + ' aria-label="Indicador de etiqueta privada" role="switch">'
+ ' <span class="slider round"></span>'
+ '</label>');
},
custom_value: function (elem, operation, value) {
if (operation === 'get') {
return $(elem).find("input[type='checkbox']").is(':checked');
} else if (operation === 'set') {
$("input[type='checkbox']", elem).val(value);
}
}
}
},
{
name: "act", align: "center", search: false,
formatter: function (cellvalue, options, rowObject) {
return '<span onClick="eliminarEtiqueta.call(this)" contenteditable="false"><button type="button" class="btn btn-sm my-0 icono-borrar" aria-label="Eliminar etiqueta" title="Eliminar etiqueta" /></span>';
}
}
],
onSelectRow: function (rowid, status, e) {
var $self = $(this), savedRow = $self.jqGrid("getGridParam", "savedRow");
if (savedRow.length > 0 && savedRow[0].id !== rowid) {
$self.jqGrid('saveRow', savedRow[0].id);
$self.setCell(savedRow[0].id, 'TipoEtiqueta', '', '', { 'title': null });
}
lastsel = rowid;
},
guiStyle: "bootstrap4",
autowidth: true,
shrinkToFit: true,
height: 'auto',
autoResizing: { compact: true },
responsive: true,
rownumbers: false,
sortorder: "desc",
altRows: true,
ignoreCase: true,
loadComplete: function (data) {
$('#numerRegistros').html(L_Grid.getGridParam("records"));
},
});
// cambia el tamaño del grid dinámicamente
$(window).bind("resize", function () {
L_Grid.jqGrid("setGridWidth", L_Grid.closest(".container").width());
}).triggerHandler("resize");
$("#txtBusqueda").on("input", function () {
var savedRow = L_Grid.jqGrid("getGridParam", "savedRow");
if (savedRow.length > 0) {
L_Grid.jqGrid('saveRow', savedRow[0].id);
L_Grid.setCell(savedRow[0].id, 'TipoEtiqueta', '', '', { 'title': null });
}
var postData = L_Grid.jqGrid("getGridParam", "postData"),
colModel = L_Grid.jqGrid("getGridParam", "colModel"),
rules = [],
searchText = $(this).val(),
l = colModel.length,
i,
cm;
for (i = 0; i < l; i++) {
cm = colModel[i];
if (cm.search !== false && (cm.stype === undefined || cm.stype === "text")) {
rules.push({
field: cm.name,
op: "cn",
data: searchText
});
}
}
postData.filters = JSON.stringify({
groupOp: "OR",
rules: rules
});
L_Grid.jqGrid("setGridParam", { search: true });
L_Grid.trigger("reloadGrid", [{ page: 1, current: true }]);
return false;
});
L_Grid.jqGrid('bindKeys', {
onEnter: function (rowid) {
L_Grid.jqGrid('editRow', rowid, true, null, null, null, {}, function () {
setTimeout(function () {
L_Grid.focus();
}, 100);
});
}
});
});
function ReloadNotsGrid(nots) {
L_Grid.jqGrid('setGridParam',
{
datatype: 'local',
data: nots
})
.trigger("reloadGrid");}
当我调用 ReloadNotsGrid
我在Edges上得到这个异常。
jquery.jqgrid.min.js 0x800a13b5 - JavaScript运行时错误。在严格模式下不允许向只读属性赋值
我找到了解决办法,我把数据以字符串的形式 "原始 "发送,我需要做的是 jQuery.parseJSON (notes)
但我得到的异常有点误导人。其他罕见的事情是,我只在MS Edges (Microsoft EdgeHTML 18.18363, Microsoft Edge 44.18362.449.0)中得到这个异常,在chrome (Version 81.0.4044.138 (Official Build) (64-bit))中,它工作得很好。
代码最终看起来像这样。
function ReloadNotsGrid(nots) {
var dataToLoad = jQuery.parseJSON(nots);
L_Grid.jqGrid('setGridParam',
{
datatype: 'local',
data: dataToLoad
})
.trigger("reloadGrid");
}