Related
Facing problem in "DOMContentLoaded" in jquery. without this jqgrid is loading , when adding this "DOMContentLoaded" not loading
document.addEventListener("DOMContentLoaded", function() {
$("#table").jqGrid({
url: ROOT + 'PCM/DataToDisplayPCM',
datatype: "JSON",
height: 'auto',
rowNum: 10,
rowList: [10, 20, 30],
colModel: [{
name: 'ProdPriority',
label: 'Priority',
index: 'ProdPriority',
width: 50
}, {
name: 'ProductCode',
label: 'Product Code',
index: 'ProductCode',
width: 80
}, {
name: 'ProductName',
label: 'Product Name',
index: 'ProductName',
width: 200
}, {
name: 'DIV',
label: 'Division',
index: 'Division',
width: 60
}, {
name: 'Category',
label: 'Categary',
index: 'Category',
width: 150
}, {
name: 'SubCategory',
label: 'SubCategary',
index: 'SubCategory',
width: 150
}, {
name: 'Priority_1',
label: 'Priority_1',
index: 'Priority_1',
width: 80
}, {
name: 'Priority1per',
label: 'Priority_1%',
index: 'Priority1per',
width: 80
}, {
name: 'Priority_2',
label: 'Priority_2',
index: 'Priority_2',
width: 80
}, {
name: 'Priority2per',
label: 'Priority_2%',
index: 'Priority2per',
width: 80
}, {
name: 'Priority_3',
label: 'Priority_3',
index: 'Priority_3',
width: 80
}, {
name: 'Priority3per',
label: 'Priority_3%',
index: 'Priority3per',
width: 80
}, ],
pager: "#prowed1",
sortname: 'P_CODE',
viewrecords: true,
sortorder: "desc"
});
jQuery("#table").jqGrid('navGrid', "#prowed1", {
edit: false,
add: false,
del: false
});
});
I am trying to design a simple risk assessment matrix in ExtJs but facing two problems.
border is missing for the cells with combobox in it.
I want to set the whole cell background red. not just a part of it.
Please look at this fiddle for better explanation.
For border you need to use config tdAttrs and for change background color of particular cell you need to use cellCls
In this Fiddle, I have created a demo using your code and used tdAttrs and cellCls.
CODE SNIPPET
Ext.create('Ext.TabPanel', {
name: 'myContainer',
id: 'myContainer',
renderTo: Ext.getBody(),
items: [{
title: 'Assessment',
name: 'assessmentPanel',
id: 'assessmentPanel',
layout: {
type: 'table',
tdAttrs: {
style: {
border: '1px solid #ccc'
}
},
// The total column count must be specified here
columns: 5
},
defaults: {
// applied to each contained panel
bodyStyle: 'padding:30px',
html: 'Risk',
scroll: false,
//border: true
//margin: '0 15 0 0'
},
items: [{
html: '<font color="white">Risk</font>',
//cellCls: 'first-row',
listeners: {
afterrender: function (view) {
console.log('view config entered!!');
//this.up('view').addCls('first-row');
//view.addCls('first-row');
}
}
}, {
html: '<b>Consequence</b>'
}, {
html: '<b>Likelihood</b>'
}, {
width: 20,
cellCls: 'noborder'
}, {
html: '<b>Risk</b>'
}, {
html: '<b>Service Interruption</b>'
}, {
xtype: 'combobox',
name: 'assessment1',
id: 'assessment1',
cellCls: 'demo',
queryMode: 'local',
displayField: 'text',
valueField: 'value',
editable: false,
cls: 'bg-trasparent',
value: 'red',
store: Ext.create('Ext.data.Store', {
data: [{
text: 'Red',
value: 'red'
}, {
text: 'Gray',
value: 'gray'
}, {
text: 'Green',
value: 'green'
}, {
text: 'Yellow',
value: 'yellow'
}, {
text: 'Blue',
value: 'blue'
}]
}),
listeners: {
select: function (combo, record) {
combo.el.dom.closest('td').style.background = record.get('value')
}
}
}, {
html: 'Cell F content'
}, {
width: 20,
cellCls: 'noborder'
}, {
html: 'Cell F content'
}, {
html: '<b>Revenue Growth</b>'
}, {
xtype: 'combobox',
name: 'assessment2',
id: 'assessment2',
value: 'Minor',
width: 130,
queryMode: 'local',
displayField: 'text',
valueField: 'value',
editable: false,
store: Ext.create('Ext.data.Store', {
data: [{
text: 'Minor',
value: 'minor'
}, {
text: 'Moderate',
value: 'moderate'
}, {
text: 'Major',
value: 'major'
}, {
text: 'Severe',
value: 'severe'
}]
})
}, {
html: 'Cell F content'
}, {
width: 20,
cellCls: 'noborder'
}, {
html: 'Cell F content'
}, {
html: '<b>Reputation</b>'
}, {
xtype: 'combobox',
name: 'assessment3',
id: 'assessment3',
value: 'Minor',
width: 130,
queryMode: 'local',
displayField: 'text',
valueField: 'value',
editable: false,
store: Ext.create('Ext.data.Store', {
data: [{
text: 'Minor',
value: 'minor'
}, {
text: 'Moderate',
value: 'moderate'
}, {
text: 'Major',
value: 'major'
}, {
text: 'Severe',
value: 'severe'
}]
})
}, {
html: 'Cell F content'
}, {
width: 20,
cellCls: 'noborder'
}, {
html: 'Cell F content'
}, {
html: '<b>Legal and Compliance</b>'
}, {
xtype: 'combobox',
name: 'assessment4',
id: 'assessment4',
value: 'Minor',
width: 130,
queryMode: 'local',
displayField: 'text',
valueField: 'value',
editable: false,
store: Ext.create('Ext.data.Store', {
data: [{
text: 'Minor',
value: 'minor'
}, {
text: 'Moderate',
value: 'moderate'
}, {
text: 'Major',
value: 'major'
}, {
text: 'Severe',
value: 'severe'
}]
})
}, {
html: 'Cell F content'
}, {
width: 20,
cellCls: 'noborder'
}, {
html: 'Cell F content'
}, {
html: '<b>Capital Items</b>'
}, {
xtype: 'combobox',
name: 'assessment5',
id: 'assessment5',
value: 'Minor',
width: 130,
queryMode: 'local',
displayField: 'text',
valueField: 'value',
editable: false,
store: Ext.create('Ext.data.Store', {
data: [{
text: 'Minor',
value: 'minor'
}, {
text: 'Moderate',
value: 'moderate'
}, {
text: 'Major',
value: 'major'
}, {
text: 'Severe',
value: 'severe'
}]
})
}, {
html: 'Cell F content'
}, {
width: 20,
cellCls: 'noborder'
}, {
html: 'Cell F content'
}, {
html: '<b>Financial</b>'
}, {
xtype: 'combobox',
name: 'assessment6',
id: 'assessment6',
value: 'Minor',
width: 130,
height: 5,
queryMode: 'local',
displayField: 'text',
valueField: 'value',
editable: false,
store: Ext.create('Ext.data.Store', {
data: [{
text: 'Minor',
value: 'minor'
}, {
text: 'Moderate',
value: 'moderate'
}, {
text: 'Major',
value: 'major'
}, {
text: 'Severe',
value: 'severe'
}]
})
}, {
html: 'Cell F content'
}, {
width: 20,
cellCls: 'noborder'
}, {
html: 'Cell F content'
}, {
height: 20,
cellCls: 'noborder'
}, {
height: 20,
cellCls: 'noborder'
}, {
height: 20,
cellCls: 'noborder'
}, {
width: 20,
height: 20,
cellCls: 'noborder'
}, {
height: 20,
cellCls: 'noborder'
}, {
html: '<b>Highest Risk</b>'
}, {
html: 'Minor'
}, {
html: 'Cell F content'
}, {
width: 20,
cellCls: 'noborder'
}, {
html: 'Cell F content'
}]
}]
});
CSS CODE
<style>
.demo {
background: red;
}
.noborder {
border: 0px !important;
}
.bg-trasparent input {
background: transparent;
color: #fff;
font-weight: bold
}
</style>
The grid displays and retrieves the data from the rest service but does not show up. I'm pretty sure I'm just missing something stupid but I've checked the documentation and a few other answers on here and nothing has fixed it. I can see in the debugger the data is coming across (which is where I pulled the sample from) and there are no JavaScript errors on the page. I also checked the data and it's valid JSON. What am I missing/doing wrong?
Code:
<table id="custSearch">
<tr><td></td></tr>
</table>
<div id="custSearchPager"></div>
$("#custSearch").jqGrid({
url : '/rebate/rest/customer/getCustomers',
datatype : 'json',
mtype : 'GET',
colNames : ['customerID', 'Company', 'First Name', 'Last Name','Address', 'City', 'State', 'Zip Code', 'Phone', 'Fax', 'EMail'],
colModel : [
{ name:'customerID', index:'customerID', width:10, sortable:false, editable: false, hidden: true},
{ name:'Company', index:'company', width:150, sortable:true},
{ name: 'First Name', index: 'firstName', length: 50, search: false},
{ name: 'Last Name', index: 'lastName', width: 80},
{ name: 'Address', index: 'address', width: 100, search: false},
{ name: 'City', index: 'city', width: 40, search: false},
{ name: 'State', index: 'state', width: 80, search: false, edittype: 'select', editoptions: { dataUrl:'/rebate/rest/state/getLookups'} },
{ name: 'Zip', index: 'zip', width: 80},
{ name: 'Phone', index: 'phone', width: 80},
{ name: 'Fax', index: 'fax', width: 80, search: false},
{ name: 'EMail', index: 'email', width: 80}
],
rowNum: 20,
rowList:[10,20,30],
pager : '#custSearchPager',
sortname : 'company',
sortorder : 'desc',
viewrecords: true,
gridview: true,
caption : 'Customers',
height: '300',
jsonReader: {cell:"", id:"customerID"}
});
jQuery("#custSearch").jqGrid('navGrid','#custSearchPager',{edit:false,add:false,del:false,search:true});
Data:
{"page":"1","total":"30","records":"20","rows":[
{"customerID":144,"firstName":"Keefe","lastName":"Abbott","company":"Vulputate LLC","address":"P.O. Box 688, 4718 Urna Street","country":"USA","city":"Detroit","state":"MI","zip":"61733","phone":"(411) 256-3885","fax":"(712) 531-0718","email":"Etiam#Integereu.org"},
{"customerID":91,"firstName":"Jerome","lastName":"Allison","company":"Vulputate Inc.","address":"Ap #519-7407 Orci Road","country":"USA","city":"Kansas City","state":"MO","zip":"22551","phone":"(245) 214-4028","fax":"(202) 531-5933","email":"sed.dolor.Fusce#risusDonec.ca"},
{"customerID":293,"firstName":"Hyacinth","lastName":"Fuentes","company":"Vulputate Corporation","address":"Ap #899-7402 Donec Road","country":"USA","city":"Jackson","state":"MS","zip":"27829","phone":"(342) 945-6263","fax":"(260) 216-3339","email":"felis.Donec.tempor#sitamet.org"},
{"customerID":235,"firstName":"Charde","lastName":"England","company":"Vulputate Associates","address":"2803 Odio Street","country":"USA","city":"Racine","state":"WI","zip":"17971","phone":"(421) 324-5019","fax":"(559) 946-7839","email":"pretium#eu.org"}
. . .
]}
The names in colModel can't contain spaces. I think you have mixed the name and the label property in colModel to display headers of the table.
The wrong in your code is that the name property does not match the data from the response and second your name property contain space, which is not allowed. To work this your colModel should be:
colModel : [
{ name:'customerID', label:'customerID', index:'customerID', width:10, sortable:false, editable: false, hidden: true},
{ name:'company', label:'Company', index:'company', width:150, sortable:true},
{ name: 'firstName', label: 'First Name', index: 'firstName', length: 50, search: false},
{ name:'lastName', label: 'Last Name', index: 'lastName', width: 80},
{ name: 'address', label: 'Address', index: 'address', width: 100, search: false},
{ name: 'city', label: 'City', index: 'city', width: 40, search: false},
{ name:'state', label: 'State', index: 'state', width: 80, search: false, edittype: 'select', editoptions: { dataUrl:'/rebate/rest/state/getLookups'} },
{ name:'zip', label: 'Zip', index: 'zip', width: 80},
{ name:'phone', label: 'Phone', index: 'phone', width: 80},
{ name: 'fax', label: 'Fax', index: 'fax', width: 80, search: false},
{ name: 'email', label: 'EMail', index: 'email', width: 80}
],
I'm trying to load data into a jqGrid sub grid (subgrid as grid) and get the above error on this line:
$("#" + subgrid_table_id).jqGrid
Please help - thanks.
My JS code:
<link rel="stylesheet" href="~/Styles/ui.jqgrid-bootstrap.css" />
<link rel="stylesheet" href="~/Styles/ui.jqgrid-bootstrap-ui.css" />
<script src="/Scripts/jquery-1.9.1.js"></script>
<script src="~/Scripts/JqGrid/jquery.jqGrid.min.js"></script>
<script src="~/Scripts/JqGrid/jquery.jqGrid.js"></script>
<script src="~/Scripts/JqGrid/grid.jqueryui.js"></script>
<script src="~/Scripts/JqGrid/grid.subgrid.js"></script>
<script src="~/Scripts/JqGrid/jqModal.js"></script>
<script src="~/Scripts/JqGrid/i18n/grid.locale-he.js"></script>
<div id="jqGrid">
<table id="grid" style="float:right; width:100%"></table>
<div id="pager" style="float:right;"></div>
</div>
<script type="text/javascript">
var gridDataUrl = 'GetAllPurchasesJson';
var lastSel;
$("#grid").jqGrid({
url: gridDataUrl,
datatype: "json",
mtype: 'POST',
jsonReader: {
root: 'gridModel',
repeatitems: true,
subgrid: {root:'rows', repeatitems: true, cell:"cell" }
}
,
colNames: ['Id','סטטוס','סה"כ כולל מע"מ','מע"מ','סה"כ ללא מע"מ','תאריך אספקה','תאריך הזמנה','ספק','מספר הזמנה'],
colModel: [
{ name: 'Id', index: 'Id', width: 50, align: 'right', hidden: true },
{
name: 'Status',
index: 'סטטוס',
width: 100,
align: 'right',
editable: true,
},
{
name: 'Total',
index: 'סה"כ כולל מע"מ',
width: 100,
align: 'right',
},
{ name: 'Vat', index: 'מע"מ', width: 100, align: 'right' },
{ name: 'TotalNoVat', index: 'סה"כ ללא מע"מ', width: 100, align: 'right' },
{ name: 'ArrivedDate', index: 'תאריך אספקה', width: 100, align: 'right', formatter: 'date', formatoptions: { srcformat: 'U', newformat: 'd/m/Y' } },
{ name: 'OrderDate', index: 'תאריך הזמנה', width: 100, align: 'right', formatter: 'date', formatoptions: { srcformat: 'U', newformat: 'd/m/Y' } },
{ name: 'Supplier', index: 'ספק', width: 100, align: 'right' },
{ name: 'OrderNumber', index: 'מספר הזמנה', width: 100, align: 'right' }
],
cmTemplate: { editable: false },
rowNum: 20,
rowList: [10, 20, 30],
height: 'auto',
width: '800',
pager: jQuery('#pager'),
sortname: 'Name',
viewrecords: true,
sortorder: "desc",
regional: 'he',
editurl: '#Url.Action("SaveOrUpdateProduct", "Inventory")',
subGrid: true,
subGridRowExpanded: function(subgrid_id, row_id) {
// we pass two parameters
// subgrid_id is a id of the div tag created within a table
// the row_id is the id of the row
// If we want to pass additional parameters to the url we can use
// the method getRowData(row_id) - which returns associative array in type name-value
// here we can easy construct the following
var subgrid_table_id;
subgrid_table_id = subgrid_id+"_t";
$("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table>");
$("#" + subgrid_table_id).jqGrid({
url:"GetPurchaseDetailes/"+row_id,
datatype: "json",
colNames: ['Id','Status','ActualTotal','ActualVat','ActualPaid'],
colModel: [
{name:"Id",index:"Id",width:80,key:true},
{name:"Status",index:"Status",width:130},
{name:"ActualTotal",index:"ActualTotal",width:80,align:"right"},
{name:"ActualVat",index:"ActualVat",width:80,align:"right"},
{name:"ActualPaid",index:"ActualPaid",width:100,align:"right",sortable:false}
],
height: '100%',
rowNum:20,
sortname: 'Id',
sortorder: "asc"
});
} });
This looks like a jQuery conflict to me: https://api.jquery.com/jquery.noconflict/
Try wrapping your jQuery in an anonymous function as below:
(function($) {
// jQuery code
})(jQuery);
Your jQuery on your page will then look something like the below:
<script type="text/javascript">
(function($) {
var gridDataUrl = 'GetAllPurchasesJson';
var lastSel;
$("#grid").jqGrid({
url: gridDataUrl,
datatype: "json",
mtype: 'POST',
jsonReader: {
root: 'gridModel',
repeatitems: true,
subgrid: {root:'rows', repeatitems: true, cell:"cell" }
}
,
colNames: ['Id','סטטוס','סה"כ כולל מע"מ','מע"מ','סה"כ ללא מע"מ','תאריך אספקה','תאריך הזמנה','ספק','מספר הזמנה'],
colModel: [
{ name: 'Id', index: 'Id', width: 50, align: 'right', hidden: true },
{
name: 'Status',
index: 'סטטוס',
width: 100,
align: 'right',
editable: true,
},
{
name: 'Total',
index: 'סה"כ כולל מע"מ',
width: 100,
align: 'right',
},
{ name: 'Vat', index: 'מע"מ', width: 100, align: 'right' },
{ name: 'TotalNoVat', index: 'סה"כ ללא מע"מ', width: 100, align: 'right' },
{ name: 'ArrivedDate', index: 'תאריך אספקה', width: 100, align: 'right', formatter: 'date', formatoptions: { srcformat: 'U', newformat: 'd/m/Y' } },
{ name: 'OrderDate', index: 'תאריך הזמנה', width: 100, align: 'right', formatter: 'date', formatoptions: { srcformat: 'U', newformat: 'd/m/Y' } },
{ name: 'Supplier', index: 'ספק', width: 100, align: 'right' },
{ name: 'OrderNumber', index: 'מספר הזמנה', width: 100, align: 'right' }
],
cmTemplate: { editable: false },
rowNum: 20,
rowList: [10, 20, 30],
height: 'auto',
width: '800',
pager: jQuery('#pager'),
sortname: 'Name',
viewrecords: true,
sortorder: "desc",
regional: 'he',
editurl: '#Url.Action("SaveOrUpdateProduct", "Inventory")',
subGrid: true,
subGridRowExpanded: function(subgrid_id, row_id) {
// we pass two parameters
// subgrid_id is a id of the div tag created within a table
// the row_id is the id of the row
// If we want to pass additional parameters to the url we can use
// the method getRowData(row_id) - which returns associative array in type name-value
// here we can easy construct the following
var subgrid_table_id;
subgrid_table_id = subgrid_id+"_t";
$("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table>");
$("#" + subgrid_table_id).jqGrid({
url:"GetPurchaseDetailes/"+row_id,
datatype: "json",
colNames: ['Id','Status','ActualTotal','ActualVat','ActualPaid'],
colModel: [
{name:"Id",index:"Id",width:80,key:true},
{name:"Status",index:"Status",width:130},
{name:"ActualTotal",index:"ActualTotal",width:80,align:"right"},
{name:"ActualVat",index:"ActualVat",width:80,align:"right"},
{name:"ActualPaid",index:"ActualPaid",width:100,align:"right",sortable:false}
],
height: '100%',
rowNum:20,
sortname: 'Id',
sortorder: "asc"
});
}
});
})(jQuery);
</script>
I am trying to show pagination of the jq grid. But it is not working. It is not showing any data in the grid. I am new in jqgrid and i have tried, here is my example.
My action in controller
public ActionResult itemList(string sidx, string sord, int page, int rows)
{
int pageIndex = Convert.ToInt32(page) - 1;
int pageSize = rows;
int totalRecords = db.tbl_Item.Count();
int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
var v = new
{
total = totalPages,
page,
records = totalRecords,
rows = (
from t in db.tbl_Item
select new
{
i = t.id,
cell = new string[]{
t.batchno,t.brand,t.buyingPrice.ToString(),
t.catg,
t.itemcode,
t.name,
t.qtyLimit.ToString(),
t.Quantity.ToString(),
t.sellingPrice.ToString(),t.supplier,t.unitType,t.vat.ToString()
}
}).ToArray()
};
return Json(v, JsonRequestBehavior.AllowGet);
}
And the javascript code are
jQuery("#list").jqGrid({
cache: false,
async: false,
url: '/Settings/itemList/',
datatype: 'json',
mtype: 'GET',
colNames: ['id','New Item', 'Batch No', 'Supplier', 'Unit', 'B. Price', 'S. Price','Item Code','Vat','Limit'],
colModel: [
{ name: 'id', index: 'id', width: 110, align: 'center',hidden:true },
{ name: 'name', index: 'name', width: 110, align: 'center' },
{ name: 'batchno', index: 'batchno', width: 110, align: 'center' },
{ name: 'supplier', index: 'supplier', width: 110, align: 'center' },
{ name: 'unitType', index: 'unitType', width: 110, align: 'center', editoptions: { readonly: 'readonly' } },
{ name: 'buyingPrice', index: 'buyingPrice', width: 110, align: 'center', editoptions: { readonly: 'readonly' } },
{ name: 'sellingPrice', index: 'sellingPrice', align: 'center' },
{ name: 'itemcode', index: 'itemcode', width: 110, align: 'center'},
{ name: 'vat', index: 'vat', width: 110, align: 'center', editoptions: { readonly: 'readonly' } },
{ name: 'qtyLimit', index: 'qtyLimit', align: 'center' }
],
pager: jQuery('#pager'),
rowNum: 2,
rowList: [5, 10, 20, 50],
sortname: 'id',
sortorder: "desc",
viewrecords: true,
width: 960,
height: 200,
loadOnce: false,
excelexport: true,
imgpath: '/scripts/themes/coffee/images',
caption: 'Stock Information'
});
Please help me.