jqgrid - columns mis-align with setGroupHeaders - jqgrid

I have an issue when my columns aren't aligned with the header only when I use setGroupHeaders. As seen in my code, I am setting the column width (as suggested in other posts). I am also using the latest version of jqgrid (just downloaded it today to see if it solves this issue).
My JS:
var jqadminagrid_data = [{}];
var wwidth = $(window).width()*.90;
var fifteen=wwidth*.06;
var onehundred=wwidth*.16;
var seventy=wwidth*.11;
var sixty=wwidth*.09;
var onetwenty=wwidth*.18;
var fiftyfive=wwidth*.08;
var eightyfive=wwidth*.13;
jQuery("#jqadminagrid").jqGrid({
url: "createadminaxml.cfm",
datatype : "xml",
height : 'auto',
colNames : ['CTR Title', 'CTR Name', '', '', 'Status Date', 'End User', 'Signed By', 'Total Cost'],
//colNames : ['CTR Title', 'CTR Name', '', 'Status Date', 'End User', 'Signed By', 'Total Cost'],
colModel : [{
name : 'title',
index : 'title',
width: onehundred
}, {
name : 'ctrname',
index : 'ctrname',
width: sixty
}, {
name : 'status',
index : 'status',
width: onehundred
},{
name : 'statusbutton',
index : 'statusbutton',
width: fiftyfive
}, {
name : 'date',
index : 'date',
width: fiftyfive
}, {
name : 'euname',
index : 'euname',
sortable: true,
width: eightyfive
}, {
name : 'signed',
index : 'signed',
width: seventy
}, {
name : 'total',
index : 'total',
width: fiftyfive
}],
rowNum : 15,
rowList : [15, 30, 45],
pager : '#pjqadminagrid',
sortname : 'ctrname',
toolbarfilter : true,
viewrecords : true,
sortorder : "asc",
autowidth : true,
});
jQuery("#jqadminagrid").jqGrid('setGroupHeaders', {
useColSpanStyle: false,
groupHeaders:[{startColumnName: 'status', numberOfColumns: 2, titleText: '<center><b>Status</b></center>'}]
});
jQuery("#jqadminagrid").navGrid("#pjqadminagrid", {
edit: false, add: false, del: false, search: false, refresh: false
});
$(window).on("resize", function () {
var newWidth = $("#jqadminagrid").closest(".ui-jqgrid").parent().width()*.95;
jQuery("#jqadminagrid").jqGrid("setGridWidth", newWidth, true);
})
Grid with no grouping
Grid with grouping
Any assistance is greatly appreciated.

Can you please, try with some other "standard" UI Theme?
We have the same demo and it is working fine. The only difference is the Theme and and the data.
If possible can you please prepare a online demo - I think the problem is either in the Theme or in the data and the way it is inserted in the Guriddo jqGrid

Related

jqgrid tree not showing like a list instead of a tree

I have the jqgrid configuration below that is supposed to supposed to show a Tree like structure. Instead I am getting a flat list structure displayed. Can somebody please tell me what I am missing?
Here are the versions I am using in the order listed in the html page:
jquery/3.2.1/jquery.min.js,
jqgrid/4.6.0/js/i18n/grid.locale-en.js,
jqueryui/1.12.1/jquery-ui.min.js
From triand.com site:
jqgrid/js/i18n/grid.locale-en.js
jqgrid/js/jquery.jqGrid.min.js
I am also using these CSS:
jqueryui/1.8.14/themes/redmond/jquery-ui.css,
jqgrid/themes/ui.jqgrid.css (from triand.com),
jqueryui/1.12.1/themes/smoothness/jquery-ui.css
in that order. My grid looks gray as opposed to the nice blue. I can't figure why.
$(document).ready(function(){
$("#list").jqGrid({
url : "/reconcile",
datatype : "json",
mtype : 'GET',
colModel : [
{name: "id",width:1,hidden:true, key:true},
{name : 'data.key.busnDate', label : 'Business Date', hidden:false, sorttype:"date", width : 80 },
{name : 'data.product', label : 'Product', sorttype:"string", width : 50, editable : false},
{name : 'data.quantityBought', label : 'Quantity Bought', sorttype:"int", width : 100, editable : false},
{"name":"level","hidden":true},
{"name":"parent","hidden":true},
{"name":"isLeaf","hidden":true},
{"name":"expanded","hidden":true},
{"name":"uiicon","hidden":true}
],
treeGrid: true,
pager : '#pager',
loadonce:false,
rowNum : 25,
height: 'auto',
rowList : [ 25,50,100,200 ],
sortname : 'key.positionId',
sortorder : 'asc',
viewrecords : true,
gridview : true,
multiselect: false,
multiboxonly: false,
autoencode: true,
caption : 'ARC Reconciliation',
emptyrecords: "No records to found for given date!",
jsonReader : {
repeatitems : true,
},
treeIcons : {
"plus": "ui-icon-circlesmall-plus",
"minus": "ui-icon-circlesmall-minus",
"leaf" : "ui-icon-document"
},
ExpandColumn: 'key.positionId'
});
jQuery("#list").jqGrid('navGrid', '#pager', {
edit : false,
add : false,
del : false,
view : true,
search : true
});
$('#datePick').datepicker({
onSelect: function (dateText, inst) {
var e = $("#list").data("events");
if (typeof (e) !== "undefined" && typeof (e.reloadGrid) !== "undefined") {
$("#list").trigger("reloadGrid");
}
}
});
});
Thanks
You can look at our new Guriddo jqGrid documentation here in order to get answer of your problem.
Additionally to this you may want to visit or tree grid demo here with a lot of new features

JqGrid Basic Grid example error when saving a new row

I am using the Basic Grid example from jqGrid Demos:
jQuery("#rowed1").jqGrid(
{
url : 'clientArray',
datatype : "local",
colNames : [ 'Inv No', 'Date', 'Client', 'Amount', 'Tax',
'Total', 'Notes' ],
colModel : [ {
name : 'id',
index : 'id',
width : 55,
editable : true,
key: true
}, {
name : 'invdate',
index : 'invdate',
width : 90,
editable : true
}, {
name : 'name',
index : 'name',
width : 100,
editable : true
}, {
name : 'amount',
index : 'amount',
width : 80,
align : "right",
editable : true
}, {
name : 'tax',
index : 'tax',
width : 80,
align : "right",
editable : true
}, {
name : 'total',
index : 'total',
width : 80,
align : "right",
editable : true
}, {
name : 'note',
index : 'note',
width : 150,
sortable : false,
editable : true
} ],
rowNum : 10,
rowList : [ 10, 20, 30 ],
pager : '#prowed1',
sortname : 'id',
viewrecords : true,
sortorder : "desc",
editurl : "clientArray",
caption : "Basic Example"
});
jQuery("#rowed1").jqGrid('navGrid', "#prowed1", {
edit : false,
add : false,
del : false
});
The following events to handle the user clicks on edit, save, and cancel buttons:
jQuery("#ed1").click(function() {
var id = jQuery('#rowed1').jqGrid('getGridParam','selrow');
jQuery("#rowed1").jqGrid('editRow', id);
this.disabled = 'true';
jQuery("#sved1,#cned1").attr("disabled", false);
});
jQuery("#sved1").click(function() {
var rowid = jQuery('#rowed1').jqGrid('getGridParam','selrow');
alert('id: ' + rowid);
jQuery("#rowed1").jqGrid('saveRow', rowid , false );
jQuery("#sved1,#cned1").attr("disabled", true);
jQuery("#ed1").attr("disabled", false);
jQuery("#aded1").attr("disabled", false);
});
jQuery("#cned1").click(function() {
var id = jQuery('#rowed1').jqGrid('getGridParam','selrow');
jQuery("#rowed1").jqGrid('restoreRow', id);
jQuery("#sved1,#cned1").attr("disabled", true);
jQuery("#ed1").attr("disabled", false);
jQuery("#aded1").attr("disabled", false);
});
jQuery("#aded1").click(function() {
jQuery("#rowed1").jqGrid('addRow', 'new');
this.disabled = 'true';
jQuery("#sved1,#cned1").attr("disabled", false);
});
And the html of the buttons:
<input type="BUTTON" id="aded1" value="Add Row" />
<input type="BUTTON" id="ed1" value="Edit row 3" />
<input type="BUTTON" id="sved1" disabled='true' value="Save row 3" />
<input type="BUTTON" id="cned1" disabled='true' value="Cancel Save" />
But the grid is not working properly because:
After saving a new row it keeps selected and I can't select others.
When I cancel the editing of a row, it deletes a few other rows.
When I click for second time
the add new row button, google chrome debugger console displays the error: Uncaught TypeError: Cannot read property 'name' of undefined
I am almost sure that it has something to do with the new row id, but after 2 days of trying I would appreciate a little help, thanks in advance
You are passing the wrong parameters to addRow. From the jqGrid documentation for addRow:
Calling convention:
jQuery("#grid_id").jqGrid('addRow',parameters);
where parameters is a object and has the following default values:
parameters =
{
rowID : "new_row",
initdata : {},
position :"first",
useDefValues : false,
useFormatter : false,
addRowParams : {extraparam:{}}
}
Also, you will want to set rowID equal to a new value each time. You can either do this explicitly or you can set it to undefined to let jqGrid assign a random ID to each new row.
For example:
jQuery("#aded1").click(function() {
var parameters = {
rowid : undefined,
initdata : {},
position :"first",
useDefValues : false,
useFormatter : false,
addRowParams : {extraparam:{}}
};
jQuery("#rowed1").jqGrid('addRow', parameters);
});

ExtJS - grid empty but store loaded

My grid is not filled, though the store is filled with json data. What is wrong?
I want all data from "csv":[...] to be written to the grid columns.
If I console.log() the store, my json data is located at store.proxy.reader.[jsonData|rawData].data.csv => Array[4]
Json Data:
{"status":{"status":0,"msg":"Ok","protocolversion":"1.1.json"},"data":{"headline":{"headline":"headline"},"csv":[{"key":"0","value":"...lugin\/monitor\/files\/logfilefilter_worker_error.log"},{"key":"1","value":"...les\/logfilefilter-worker01-progress.log.1331769600"},{"key":"2","value":"...\/application\/x\/plugin\/monitor\/files\/Test.log"},{"key":"3","value":"...ind\/plugin\/monitor\/files\/logfile_for_navi_test.log"}]}}
Model:
Ext.define( 'Monitor.model.ComboLogfiles', {
extend: 'Ext.data.Model',
fields: [ {name: 'key'}, {name: 'value'} ]
} );
Store:
Ext.define( 'Monitor.store.ComboLogfiles', {
extend : 'Ext.data.Store',
model : 'Monitor.model.ComboLogfiles',
proxy : {
type : 'ajax',
url : '/devel/phi/dev/04-presentation/http-api/index.php',
extraParams: {
user : 'test',
pass : 'test',
vers : '1.1.json',
module : 'monitor',
func : 'getLogfiles'
},
reader : {
type: 'json',
root: 'csv'
// root: 'data'
}
},
autoLoad: true
} );
Controller
var store = Ext.create('Monitor.store.ComboLogfiles');
oLogfileSelector = Ext.create("Ext.window.Window", {
title: 'Logfiles',
width: '200',
height: '400',
autoScroll: true,
flex: 1,
minimizable: false,
maximizable: false,
style: 'background-color: #fff;',
items: [{
xtype: 'panel',
items: [
Ext.create('Ext.grid.Panel', {
id: 'mygrid',
store: store,
width: 200,
height: 200,
title: 'Logfiles',
columns: [
{
text: 'Key',
width: 50,
sortable: false,
dataIndex: 'key'
}
,{
text: 'File',
width: 100,
sortable: false,
dataIndex: 'value'
}
]
})
]
}]
}).show();
Maybe try like this:
reader: {
type: 'json',
root: 'data.csv',
successProperty:false
}

Ext.js 4 window with form cals servlet which returns JSON but unable to populate gridpanel

I am using Ext.js 4 with MVC. I have a window which pops up, and asks the user for some criteria. That window calls a servlet, which returns the data as JSON, and should then populate a grid. I can see thru Firefly that the JSON object IS be returned. However, the grid is not being populated. The reason is that a subsequent call to the servlet is beign made. This is because I have the URL specified in two places. I know this is wrong, but if either one is omitted I get error messages.
This is app/controller/PSLocators.js
Ext.define('MyApp.controller.PSLocators', {
extend: 'Ext.app.Controller',
stores: [ 'PSLocators' ],
models: [ 'PSLocator' ],
views : [ 'pslocator.List' ]
});
This is app/model/PSLocator.js
Ext.define('MyApp.model.PSLocator',
{
extend: 'Ext.data.Model',
fields:
[
'id',
'name',
'address',
'city',
'state',
'zip',
]
});
This is app/store/PSLocators.js. This has the first of the urls. This is the one that returns no data. I don't think I should have the proxy{} here, but if I delete the proxy { } I get the error message
uncaught exception: [Exception... "'You are using a ServerProxy but have not supplied it with a url.' when calling method: [nsIDOMEventListener::handleEvent]"
nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)"
location: "JS frame :: chrome://firebug/content/net/spy.js :: callPageHandler :: line 812" data: no]"
Ext.define('MyApp.store.PSLocators', {
extend: 'Ext.data.Store',
model: 'MyApp.model.PSLocator',
autoLoad: false, // see also activate() in grid panel
sortOnLoad: false, // sorted by SAS
proxy:
{
type: 'ajax',
url: MyGlobalData.contextPath + '/PSLocator',
reader:
{
type: 'json',
root: 'data', // the name of the array within the JSON dataset
totalProperty: 'results',
successProperty: 'success'
}
}
});
This is the app/view/pslocator/List.js. This has the second of the urls. This url is returning the data correctly as JSON. If I delete the url I get the error message "uncaught exception: No URL specified"
Ext.define('MyApp.view.pslocator.List' ,{
extend: 'Ext.grid.Panel',
alias : 'widget.pslocatorlist',
store : 'PSLocators',
title : 'Store Locator',
id : 'pslocator.List',
autoScroll: true,
height: 400,
columnLines: true,
initComponent: function()
{
this.columns = [
{header: 'ID' , dataIndex: 'id' , flex: .05 , align: 'center' },
{header: 'Name' , dataIndex: 'name' , flex: .20 , align: 'left' },
{header: 'Address' , dataIndex: 'address' , flex: .20 , align: 'left' },
{header: 'City' , dataIndex: 'city' , flex: .10 , align: 'left' },
{header: 'State' , dataIndex: 'state' , flex: .05 , align: 'center' },
{header: 'Zip' , dataIndex: 'zip' , flex: .05 , align: 'center' }
];
this.callParent(arguments);
},
listeners:
{
activate: function()
{
this.un('activate', arguments.callee);
var win = new Ext.Window(
{
id: 'id-pslocator-window',
title: 'Show locations near which store?',
items: [
{
xtype : 'form',
id : 'id-pslocator-form',
bodyPadding: 5,
width : 500,
height : 125,
autoScroll : false,
// The form will submit an AJAX request to this URL when submitted
url: MyGlobalData.contextPath + '/PSLocator',
layout: 'auto',
defaults:
{
anchor: '100%'
},
items: [
{
xtype : 'textfield',
fieldLabel : 'Store number',
name : 'pStoreNumber',
labelWidth : 200,
width : 300, // includes labelWidth
allowBlank : false,
regex : /^([0-9]+)([ ]*)$/,
regexText : 'Must be a single unsigned integer.',
}
],
// Reset and Submit buttons
buttons: [
{
text: 'Reset',
handler: function()
{
this.up('form').getForm().reset();
}
},
{
text: 'Submit',
formBind: true, //only enabled once the form is valid
disabled: true,
handler: function()
{
var form = this.up('form').getForm();
if (form.isValid())
{
form.submit(
{
success: function(form, action)
{
console.log('In success function');
var myGrid = Ext.getCmp('id-pslocator-panel');
console.log('myGrid = ' + myGrid);
var myStore = myGrid.getStore();
console.log('myStore = ' + myStore);
myStore.load(); /* requires store be defined as above */
myGrid.getView().refresh();
var myPopup = Ext.getCmp('id-pslocator-window');
myPopup.destroy();
} // end success function
}); // end form submit
} // end if is valid
} // end handler
} // end submit
] // end buttons
}] // end items
}); // end win
win.show();
// this.store.load();
}
}
}); // Ext.define
Can someone please help, or point me to a working example (reminder: I am attempting the use the MVC architecture.)
You should store the proxy configuration in the model rather than the store in ExtJS4. Also It looks like you are just wanting to limit the search on your stores to a particular store number. You shouldn't need to submit a POST request via the form to do this. You should add a filter to your store so the server can return the correct data.
DISCLAIMER: I've not tested this code out, but it should be enough to get you going.
app/model/PSLocator.js
Ext.define('MyApp.model.PSLocator',
{
extend: 'Ext.data.Model',
fields:
[
'id',
'name',
'address',
'city',
'state',
'zip',
],
proxy:
{
type: 'ajax',
url: MyGlobalData.contextPath + '/PSLocator',
reader:
{
type: 'json',
root: 'data', // the name of the array within the JSON dataset
totalProperty: 'results',
successProperty: 'success'
}
}
});
app/store/PSLocators.js
Ext.define('MyApp.store.PSLocators', {
extend: 'Ext.data.Store',
model: 'MyApp.model.PSLocator',
autoLoad: false, // see also activate() in grid panel
sortOnLoad: false, // sorted by SAS,
remoteFilter: true // Needed so filter changes will go to the server
});
app/view/pslocator/List.js
Ext.define('MyApp.view.pslocator.List' ,{
extend: 'Ext.grid.Panel',
alias : 'widget.pslocatorlist',
store : 'PSLocators',
title : 'Store Locator',
id : 'pslocator.List',
autoScroll: true,
height: 400,
columnLines: true,
initComponent: function()
{
this.columns = [
{header: 'ID' , dataIndex: 'id' , flex: .05 , align: 'center' },
{header: 'Name' , dataIndex: 'name' , flex: .20 , align: 'left' },
{header: 'Address' , dataIndex: 'address' , flex: .20 , align: 'left' },
{header: 'City' , dataIndex: 'city' , flex: .10 , align: 'left' },
{header: 'State' , dataIndex: 'state' , flex: .05 , align: 'center' },
{header: 'Zip' , dataIndex: 'zip' , flex: .05 , align: 'center' }
];
this.callParent(arguments);
}
}); // Ext.define
app/view/pslocator/Window.js
Ext.define('MyApp.view.pslocator.Window', {
extend: 'Ext.Window',
alias: 'widget.storeselector',
id: 'id-pslocator-window',
title: 'Show locations near which store?',
items: [
{
xtype : 'form',
id : 'id-pslocator-form',
bodyPadding: 5,
width : 500,
height : 125,
autoScroll : false,
// The form will submit an AJAX request to this URL when submitted
url: MyGlobalData.contextPath + '/PSLocator',
layout: 'auto',
defaults:
{
anchor: '100%'
},
items: [
{
xtype : 'textfield',
fieldLabel : 'Store number',
name : 'pStoreNumber',
labelWidth : 200,
width : 300, // includes labelWidth
allowBlank : false,
regex : /^([0-9]+)([ ]*)$/,
regexText : 'Must be a single unsigned integer.',
}
],
// Reset and Submit buttons
buttons: [
{
text: 'Reset',
handler: function()
{
this.up('form').getForm().reset();
}
},
{
text: 'Submit',
formBind: true, //only enabled once the form is valid
disabled: true,
handler: function()
{
var form = this.up('form').getForm();
if (form.isValid())
{
this.fireEvent('storeselected', form.getValues().pStoreNumber);
this.destroy();
} // end if is valid
} // end handler
} // end submit
] // end buttons
}] // end items
});
app/controller/PSLocators.js
Ext.define('MyApp.controller.PSLocators', {
extend: 'Ext.app.Controller',
stores: [ 'PSLocators' ],
models: [ 'PSLocator' ],
views : [ 'pslocator.List' ],
init: function() {
this.control({
'pslocatorlist': {
activate: this.showStoreSelector
},
'storeselector': {
storeselected: this.updatePSLocatorStore
}
);
},
showStoreSelector: function()
{
var win = Ext.create('MyApp.view.pslocator.Window');
win.show();
},
updatePSLocatorStore: function(storeId) {
this.getPSLocationsStore().filter('id', storeId);
this.getPSLocationsStore().load(); // I can't remember if this step is needed.
}
});
I think thats about as best I can get it from reading over the code. It should give you an idea of how you can use the MVC technique to your advantage and hopefully get you on the right path.

Unable to sort data in ExtJS DataGrid when grouped

I'm using ExtJS 3.3.0 with a datagrid that consumes a JSON data store (Ext.data.GroupingStore).
When I'm not grouping by a column, I can sort just fine, however when grouping by a column, the sort algorithm seems to fall apart.
I have another data grid that does server side sorting (and grouping and paging) and this works just fine. Comparing the the code between the two has left me stumped for the difference that's making one work and the other not work.
Many thanks in advance.
CW.App.FileGrid = {
store : null,
initComponent: function(){
this.store = new Ext.data.GroupingStore({
autoLoad:true,
url:'/sites/files.js',
groupField:'modified',
// Sort by whatever field was just grouped by. This makes the data
// make more sense to the user.
groupOnSort:true,
remoteSort:false,
remoteGroup:false,
sortInfo:{
field:'modified',
direction:'DESC'
},
reader: new Ext.data.JsonReader({
idProperty:'filename',
root:'data',
fields: [
'iconCls',
{
name: 'modified',
type: 'date',
dateFormat:'timestamp'
},
'description', 'folder', 'filename',
'filesize', 'ext', 'dateGroup']
})
});
// this.store.setDefaultSort('modified', 'DESC');
Ext.apply(this, {
store: this.store,
loadMask:true,
columns: [
{
xtype:'actioncolumn',
items:[{
getClass:function(v,meta,rec){
return rec.get('iconCls');
}
}],
width:25
},{
id:'filename',
header: "Filename",
sortable: true,
dataIndex: 'filename'
},{
id:'ibmu',
header: "iBMU",
width:50,
sortable:true,
dataIndex: 'folder'
},{
id:'date',
header: "Date",
width: 65,
sortable: true,
dataIndex: 'modified',
renderer: Ext.util.Format.dateRenderer('Y-m-d h:i'),
groupRenderer:function(v,unused,r,rowIdx,colIdx,ds){
return r.data['dateGroup'];
}
},{
id:'type',
header: "Type",
width: 70,
sortable: true,
dataIndex: 'description'
},{
id:'size',
header: "Size",
width: 50,
sortable: true,
dataIndex: 'filesize',
renderer: Ext.util.Format.fileSize
},{
xtype:'actioncolumn',
items:[{
icon: '/img/fam/drive_disk.png',
tooltip: 'Download file',
handler: function(grid, rowIndex, colIndex){
var rec = store.getAt(rowIndex);
location.href = Ext.urlAppend('/ibmus/download/', Ext.urlEncode({
folder: rec.get('folder'),
filename: rec.get('filename')
}));
}
}]
}
],
autoExpandColumn:'filename',
view: new Ext.grid.GroupingView({
emptyText: 'No files found. Please wait up to 24 hours after activating your account for files to appear.',
forceFit:true,
groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Files" : "File"]})'
}),
frame:false,
width: '100%',
height: 250,
collapsible: false,
animCollapse: false
});
CW.App.AlarmGrid.superclass.initComponent.call(this);
}
};

Resources