Forum
By Looking at the methods you have provided, it appears to me that the requirement I am looking for is doable. After the grid is loaded, if someone wants to group all the rows by a specific column, we should have a method to do the following:
Sort the grid on the column which user wants to do groupby
Add a row at the end of column value change
Add a header with the unique value of the column name in that block with the number of rows in that group. This is the feature that lot of users are looking for to closely look at the results in the grid
I used the existing jqGrid features and simulated the groupBy funtion. This is what I need and it works for me. If a better feature can be provided by jqGrid native code, that will be wonderful. Here is the function I created
function groupBy1(grid,field)
{
// grid ==> Name of the grid field
// field ==> id name of the field
// example ==> groupBy1("#list2","name")
// row ==> this is one of the id used to display the row number
// and can not be used for group by. If used, it will ungroup
// the grid
var txt=field;
var mya=new Array(); // array to hold all the rowid of this grid
mya=jQuery("#list2").getDataIDs(); // Get All IDs
for(i=0;i<mya.length;i++)
{
data=jQuery(grid).getRowData(mya[i]); // get the row data
if(data["row"]=="")jQuery(grid).delRowData(mya[i]); // if the row does not contain any value,
} // delete the row (ungroup)
if(field=="row") // just ungroup and return ; else
{
jQuery(grid).setGridParam({sortname:txt,sortorder: "asc",}).trigger('reloadGrid');
return;
}
jQuery(grid).setGridParam({sortname:txt}).trigger('reloadGrid');// sort the grid using the field name
mya=jQuery("#list2").getDataIDs(); // Get All IDs (after deletioo - ungroup)
var data=jQuery(grid).getRowData(mya[1]); // Get First row to get the labels
var oldValue=data[txt]; // first value
var insertHere=mya[0]; // rowid where the group text has to be inserted
var groupCount=0; // number of rows in the group
var dat=new Array(); // array to store the gheader value
for(i=0;i<mya.length;i++) // loop thru all rows
{
data=jQuery(grid).getRowData(mya[i]); // get the row contents
if(oldValue!=data[txt]) // if the field value is not same
{
var value=oldValue+" - "+groupCount; // Set the test
dat[txt]=value; // set the field value
jQuery(grid).addRowData(insertHere,dat, 'before', insertHere); // insert group header
jQuery(grid).setCell(insertHere,field,'',{color:'red','text-align':'left','font-weight':'bold'}); // set color
insertHere=mya[i]; // reset where to insert group header
groupCount=0; // reset group count
oldValue=data[txt]; // rest old value
}
else
groupCount++; // update group count
}
var value=oldValue+" - "+groupCount; // set group text for last entry
dat[txt]=value; // set the value
jQuery(grid).addRowData(insertHere,dat, 'before', insertHere); // add the group header
jQuery(grid).setCell(insertHere,field,'',{color:'red','text-align':'left','font-weight':'bold'});// set the color
}
I tested the function using following snippet
<input type="BUTTON" id="bexportid" value="GroupBy" onclick='var m=$("grby").value;groupBy1("#list2",m);' />
<select id='grby'>
<option value='row'>UnGroup</option>
<option value='invdate'>inv date</option>
<option value='name'>name</option>
<option value='note'>note</option>
<option value='amount'>amount</option>
<option value='tax'>tax</option>
<option value='total'>total</option>
</select>
03:26
Moderators
30/10/2007
Hello,
Thanks for the code. Could you please send me the code to: tony at trirand dot com. It is maybe the first step for this feature.
Best Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
55 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66