0
我的產品網格和我的工作搜索件現在,當我點擊放大鏡我在grid.addons.js文件得到一個錯誤:自由jqGrid的搜索按鈕不起作用的onclick
oprtr[j] = {op:stempl[j],text: p.odata[j].text};
Uncaught TypeError: Cannot read property '0' of undefined.
我確定這是因爲我正在做的事情,有人可以看看我的網格,並告訴我爲什麼它不起作用?
$("#productsTable").jqGrid({
data: parsedResult,
datatype: "local",
loadonce: true,
height: 'auto',
marginLeft: 'auto',
colNames: [
'Product Id', 'Add', 'Product Name', 'Product Code', 'Customer Price'
],
colModel: [
{ name: 'Id', width: 0, hidden:true },
{ name: "actions", template: "actions", width: 50, formatoptions:{
delbutton: false,
editbutton: false
} },
{ name: 'Name', index: 'Name', width: 550, searchoptions:{sopt:['eq','bw','bn','cn','nc','ew','en']} },
{ name: 'ProductCode', index: 'ProductCode', width: 150, searchoptions:{sopt:['eq','bw','bn','cn','nc','ew','en']} },
{ name: 'Price', index: 'Price', width: 100, formatter: 'currency', formatoptions:{decimalSeparator:".", thousandsSeparator: ",", decimalPlaces: 2, prefix: "$"},
searchoptions:{sopt:['eq','ne','le','lt','gt','ge']}}
],
rowNum: 15,
rowList: [5, 10, 15, 20],
pager: true,
gridView: true,
viewrecords: true,
iconSet: "jQueryUI",
sortname: 'Name',
sortorder: 'asc',
inlineEditing: { keys: false },
search: true,
actionsNavOptions: {
addToCarticon: "ui-icon-cart",
addToCarttitle: "Add item to the cart",
custom: [
{ action: "addToCart", position: "first", onClick: function (options) {
var rowData = $('#productsTable').getRowData(options.rowid);
var cartButton = $(".ui-icon", "#jAddToCartButton_"+options.rowid);
if(cartButton.hasClass("ui-icon-cancel")){
cart.shift(rowData);
cartButton.removeClass("ui-icon-cancel");
cartButton.addClass("ui-icon-cart");
}
else if(cartButton.hasClass("ui-icon-cart")){
cart.push(rowData);
cartButton.removeClass("ui-icon-cart");
cartButton.addClass("ui-icon-cancel");
}
}
}]
},
loadComplete: function() {
$("#add-product-dialog-loading-message").hide();
$(".spinner").hide();
$("#add-product-dialog-form").dialog("open");
//for each object in cart
//if product ID matches product Id in product
//grid then set button to a cancel icon
if(cart.length !== 0){
var cartIds = [];
var jsonCart = JSON.stringify(cart);
var parsedJsonCart = JSON.parse(jsonCart);
var productsInCart = $.grep(parsedJsonCart, function(el,i){
cartIds.push(el.Id);
});
var currentRows = $('#productsTable').getRowData();
var shownProductsThatAreInCart = $.grep(currentRows, function (el, i) {
return $.inArray(el.Id, cartIds) !== -1;
});
if(shownProductsThatAreInCart.length > 0){
var rowIds = $(this).jqGrid('getDataIDs');
$.each(rowIds, function(k, v) {
rowData = $('#productsTable').getRowData(v);
if($.inArray(rowData['Id'], cartIds) !== -1){
alert("Matched Product:\nRowData['id'] = " + rowData['Id'] + "\nto\nProduct in cart: " + cartIds.Id);
$(".ui-icon", "#jAddToCartButton_"+v).removeClass("ui-icon-cart");
$(".ui-icon", "#jAddToCartButton_"+v).addClass("ui-icon-cancel");
}
});
}
}
},
gridComplete: function() {
}
});
$("#productsTable").jqGrid("navGrid", {edit:false,add:false,del:false}).jqGrid("filterToolbar", {searchOperators : true});
我包括有:
value="https://code.jquery.com/jquery-1.10.2.min.js" />
value="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js" />
value="https://cdnjs.cloudflare.com/ajax/libs/jquery.ui-contextmenu/1.11.0/jquery.ui-contextmenu.min.js" />
value="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.9.2/js/jquery.jqgrid.min.js" />
value="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.9.2/js/i18n/grid.locale-en.js" />
value="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.9.2/plugins/grid.setcolumns.js" />
value="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.9.2/plugins/jquery.contextmenu.js" />
value="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.9.2/plugins/jquery.searchfilter.js" />
value="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.9.2/plugins/ui.multiselect.js" />
value="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.9.2/plugins/grid.postext.js" />
value="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.9.2/plugins/grid.addons.js" />
謝謝!
你應該**刪除**'grid.addons.js'。你需要什麼方法從文件?而且,你的代碼中'loadComplete'部分應該做什麼? – Oleg
大聲笑它做到了..我的印象是,如果我使用網格,我必須擁有所有額外的內容,我一直在搞這個問題好幾天,而我所要做的只是刪除那些包含,謝謝。許多! – Blindsyde
loadcomplete是處理分頁,當我分頁或改變排序我會失去以前標記/編輯的行,所以我通過購物車陣列和當前行數組循環,看看我是否有匹配,如果有匹配,然後我將該行標記爲/編輯/添加到購物車。 – Blindsyde