JQGrid : How to create a drop-down on the column header - drop-down-menu

I want to create a drop-down list on JQGrid header column and populate the drop-down with values from the Velocity template Array.
I have the following code :
$(document).ready(function() {
$("#activityTab").jqGrid(
{
datatype : "local",
width: 100,
colNames : [
headers.date, headers.method,
"javascript:showDropDown();",
headers.payFrom,
headers.confirmCode, headers.amount,headers.status ],
colModel : [ {
......
How can I call a method to populate the a particular header column as above.

Related

How do I programmatically select from a select2 dropdown when using the tablesorter.filterformatter widget?

I would like to be able to programmatically select something from a dropdown, as in http://select2.github.io/select2/#programmatic. But the dropdown also seems to be generated (I didn't include it anywhere in the HTML) by the filterformatter widget, which I initialized with:
$('#client_table').tablesorter({
theme: "blue",
headers: {1: {sorter: 'types'}},
widgets: ["filter", "zebra"],
widgetOptions : {
filter_formatter: {
1 : function ($cell, indx) {
return $.tablesorter.filterFormatter.select2($cell, indx, {
closeOnSelect: false,
placeholder: "Select events",
allowClear: true,
match: false, // exact match only
});
},
What element do I call select2 on in this case? What are the values/data that I should be using (the thing I would like to select, for example, is the string APP_STATE).
When select2 is applied to the table, the table cell gets a class name of select2col0 where (0 is the column zero-based index).
If you open this demo and enter the following code in the console, it'll programmically set the value:
$('.select2col0').find('input').select2('val', ['abc']);

Getting jqGrid group column header values

I am using jquery 1.7.1. I am using group headers in jqGrid. i can get the column names using this code $("#_My_Grid").jqGrid('getGridParam','colNames');. Like this how can i get group header column names? i have shown group headers in my grid by using this code
$("#_My_Grid").jqGrid('setGroupHeaders', {
useColSpanStyle: false,
groupHeaders:[
{startColumnName: 'amount', numberOfColumns: 3, titleText: 'Price'},
{startColumnName: 'closed', numberOfColumns: 2, titleText: 'Shipping'}
]
});
I just want the values Price,Shipping. Can anybody resolve this..
The options of of setGroupHeaders method will be saved in internal groupHeader option of jqGrid. So you can use the following code to access the values "Price" and "Shipping":
var groupHeadersOptions = $("#_My_Grid").jqGrid("getGridParam", "groupHeader"));
alert(groupHeadersOptions.groupHeaders[0].titleText); // displays "Price"
alert(groupHeadersOptions.groupHeaders[1].titleText); // displays "Shipping"

jqGrid text Sort Order

I have a jqGrid that I set up like this
gridAltMpn.jqGrid({
autowidth: true,
shrinkToFit: true,
datatype : 'local',
data : input,
height : '100',
scrollrows: true,
scrollOffset : '0',
hidegrid : false,
colNames : [ 'P', 'MPN' ],
colModel : [
{ name : 'Col1', width : 30, align:'center' },
{ name : 'Col2', width : 250, sorttype: 'integer'}
],
pager : '#altmpn_pager',
pagerpos : 'left',
scroll: 50,
gridview : true,
caption : 'A useful table title',
emptyRecordText : '<div id="no_data_msg" style="text-align:center"> No Results Found</div>',
hoverrows : true,
onSelectRow: function(id) {
var gsr = gridAltMpn.jqGrid('getGridParam', 'selrow');
if (gsr) {
var rowData = gridAltMpn.jqGrid('getRowData', gsr);
if ($("input[name='optInvInqType']:checked").val() == 'MPN') {
getInvInq("MPN", rowData.MPN);
}
}
},
loadComplete: function() {
gridAltMpn.setSelection(gridAltMpn.getDataIDs()[0], true);
}
});
The data in this grid looks like this
XX 774860A6
774860A8
774860A4
774860A3
774860A10
STARTER, PNEUM,PW4000
When the grid is first loaded that it fine but if the user wants to sort by the second column it ends up like this
774860A10
774860A3
774860A4
XX 774860A6
774860A8
STARTER, PNEUM,PW4000
The 774860A10 should go after the 774860A8 just like in an integer sort. I cannot use an integer sort because these are not integers as there is some alpha characters in there. In other words I want a text entry to sort like an integer. Do I need to use a custom sort routine and then have my Javascript to do a integer like sort? I also don't need this sorted on the first time because my server sorts it by the first column. The user might want it sorted by the second column
You should use a custom function for this type of sorting.
For this, set sort type property of jqgrid as your custom function. As stated in this link, sort type can have the following values.
sorttype:
int/integer - for sorting integer
float/number/currency - for sorting decimal numbers
date - for sorting date
text - for text sorting
function - defines a custom function for sorting. To this function we pass the value to be sorted and it should return a value too.
And the custom function can be something like this: (From this link found in the answer by Oleg for this question.)
colModel: [
{name:'Posn', index:'Posn', width:100, sorttype:
function(cell)
{
//Here you have to apply your own logic
if (cell=='GK') return '0';//returns the sort order
if (cell=='DEF') return '1';
if (cell=='MID') return '2';
if (cell=='STR') return '3';
}
},
By the way, you can set the sortname property of jqgrid to set a column for initial loadtime sorting.

Kendo UI: Place Grid Summary Values in Footer

Using the Kendo UI Grid and MVC 4, I haven't been able to find a way to put summary totals (financial) at the bottom of the grid for select columns.
Is this possible?
Yes indeed! check DataSource Aggregate.
Example:
var stocksDataSource = new kendo.data.DataSource({
transport:{
read:function (options) {
}
},
schema :{
model:{
fields:{
name :{ type:"string" },
price:{ type:"number" }
}
}
},
aggregate:[
{ field:"price", aggregate:"sum" }
],
pageSize :10
});
I have defined a DataSource with two fields: the items name and price. I want to totalize the price so I defined an aggregate for price and what I'm going to do is sum (you can also min, max, average and count).
Then in the Grid when I define the columns I write:
columns :[
{ field:"name", title:"Product" },
{ field:"price", title:"Price", footerTemplate:"Sum: #= sum # " }
],
And that's it!

Paging does not work in JqGrid

I am using jQGrid Latest version in my project.following is complete configuration that i configured.
jQuery("#list").jqGrid( {
url : 'Link.do?method=findAllBrand',
mtype : 'GET',
height : 350,
datatype : "xml",
colNames : [ 'Name' ],
colModel : [ {
name : 'name',
index : 'name',
width : 620
} ],
rowNum : 10,
rowList : [ 10, 20, 30 ],
sortname : 'id',
sortorder : "desc",
viewrecords : true,
multiselect : true,
imgpath : 'themes/base/images',
caption : "Brand (s) Summary Grid",
pager : #pager,
cache : false,
onSelectRow : function(id) {
}
});
I am getting following data in form of xml from server :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><rows><page>1</page><total>4</total><records>75</records><row id="BRD00005"><cell>AEG</cell></row><row id="BRD00010"><cell>ARC</cell></row><row id="BRD00006"><cell>Aga</cell></row><row id="BRD00007"><cell>Allenzi </cell></row><row id="BRD00008"><cell>Amana</cell></row><row id="BRD00009"><cell>Andi</cell></row><row id="BRD00011"><cell>Arda</cell></row><row id="BRD00012"><cell>Ariston</cell></row><row id="BRD00013"><cell>Asko</cell></row><row id="BRD00014"><cell>Baumatic</cell></row><row id="BRD00015"><cell>Bendix</cell></row><row id="BRD00003"><cell>Blanco</cell></row><row id="BRD00001"><cell>Bosch</cell></row><row id="BRD00004"><cell>Chef</cell></row><row id="BRD00016"><cell>Damani</cell></row><row id="BRD00017"><cell>Davell</cell></row><row id="BRD00018"><cell>Delonghi</cell></row><row id="BRD00019"><cell>Dishlex</cell></row><row id="BRD00020"><cell>Electrolux</cell></row><row id="BRD00021"><cell>Emilia</cell></row><row id="BRD00022"><cell>Euro</cell></row><row id="BRD00023"><cell>Eurolec</cell></row><row id="BRD00024"><cell>Euromaid</cell></row><row id="BRD00002"><cell>F&P</cell></row><row id="BRD00027"><cell>FP</cell></row><row id="BRD00025"><cell>Fagor</cell></row><row id="BRD00026"><cell>Fisher And Paykel</cell></row><row id="BRD00028"><cell>Franke</cell></row><row id="BRD00030"><cell>GE</cell></row><row id="BRD00034"><cell>GVA</cell></row><row id="BRD00029"><cell>Gaggenau</cell></row><row id="BRD00031"><cell>Glem </cell></row><row id="BRD00032"><cell>Glem Gas</cell></row><row id="BRD00033"><cell>Glemgas</cell></row><row id="BRD00035"><cell>Haier</cell></row><row id="BRD00036"><cell>Hisense </cell></row><row id="BRD00037"><cell>Hitachi</cell></row><row id="BRD00038"><cell>Hoover</cell></row><row id="BRD00039"><cell>Hotpoint</cell></row><row id="BRD00040"><cell>IAG</cell></row><row id="BRD00041"><cell>Ilve</cell></row><row id="BRD00042"><cell>Indesit</cell></row><row id="BRD00043"><cell>Jenn Air</cell></row><row id="BRD00044"><cell>Kelvinator </cell></row><row id="BRD00045"><cell>Kleenmaid</cell></row><row id="BRD00047"><cell>LG</cell></row><row id="BRD00046"><cell>La Germania</cell></row><row id="BRD00048"><cell>Liebherr</cell></row><row id="BRD00049"><cell>Linea</cell></row><row id="BRD00050"><cell>Lofra</cell></row><row id="BRD00051"><cell>Maytag</cell></row><row id="BRD00052"><cell>Midea</cell></row><row id="BRD00053"><cell>Miele</cell></row><row id="BRD00054"><cell>NEC</cell></row><row id="BRD00055"><cell>Neff</cell></row><row id="BRD00056"><cell>Nobel</cell></row><row id="BRD00057"><cell>Omega</cell></row><row id="BRD00058"><cell>Onix</cell></row><row id="BRD00059"><cell>Panasonic </cell></row><row id="BRD00060"><cell>Robinhood</cell></row><row id="BRD00061"><cell>Sagi</cell></row><row id="BRD00062"><cell>Samsung</cell></row><row id="BRD00063"><cell>Seimen </cell></row><row id="BRD00064"><cell>Sharp</cell></row><row id="BRD00065"><cell>Simpson</cell></row><row id="BRD00066"><cell>Smeg</cell></row><row id="BRD00067"><cell>St George</cell></row><row id="BRD00068"><cell>Technika</cell></row><row id="BRD00069"><cell>Techno</cell></row><row id="BRD00070"><cell>Technogas</cell></row><row id="BRD00071"><cell>Teka</cell></row><row id="BRD00072"><cell>Thor</cell></row><row id="BRD00073"><cell>Vintec</cell></row><row id="BRD00074"><cell>Westinghouse</cell></row><row id="BRD00075"><cell>Whirlpool</cell></row></rows>
I have modified the pager parameter as suggested by user Oleg in the other post.but still the pager is not working as expected. initially it shows only the 10 data of the record , when i click on next it does nothing.
what did i do wrong
Thank You
Mihir Parekh
The value of pager option must be quoted: pager : "#pager". You use datatype: "xml" without loadonce: true. In the case your server (url : 'Link.do?method=findAllBrand') is responsible for paging and sorting. If the user click on the next page new request to the server with the corresponding parameters page=2.
Typically the server should return the number of items which corresponds page and rows parameters. The XML response contains much more items. I suppose that the server returns all items independent from the requested page. In the case you should include loadonce: true. In the case the client code (JavaScript code of jqGrid) will do paging and sorting for you. If you use loadonce: true option you can remove the part
<page>1</page><total>4</total><records>75</records>
from the XML data returned from the server.
Additionally I would recommend you to consider to change to use JSON instead of XML whenever it's possible. In the case you could reduce the representation of items like
<rows>
<row id="BRD00022"><cell>Euro</cell></row>
<row id="BRD00002"><cell>F&P</cell></row>
<row id="BRD00026"><cell>Fisher And Paykel</cell></row>
</rows>
to
[["Euro","BRD00022"],["F&P","BRD00002"],["Fisher And Paykel","BRD00026"]]
So you can reduce the size of transferred data.
Additionally, like I wrote you in the comment to your previous question, you should replace sortname : 'id' to sortname : 'name' bacsue your grid don't have the column with the name "id". The option sortorder : "desc" should be probably removed.
You should remove deprecated option imgpath and remove option cache which not exist in jqGrid too. Instead of that I strictly recommend you to add gridview: true option and autoencode: true. If you use autoencode: true you will don't need to use HTML encoding (converting F&P to F&P on the server side).
UPDATED: The demo demonstrate how the grid could looks like:
I included toolbar filter and advanced searching in the grid to show how easy one can implement the features if one uses loadonce: true.

Resources