Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Sorting xml and combining columns
07/10/2008
06:23
Avatar
theosoft
theosoft
Member
Members
Forum Posts: 3
Member Since:
07/10/2008
sp_UserOfflineSmall Offline

I have a xml file I'm pulling into a grid.

I'm using the xmlmap to pull into the grid.

The issue I'm having is attempting to sort the various columns.

It won't sort at all, even using sorttype.

Should I pass the xml into an xmlstr? This would seem kind of cumbersome.

On another note, I would like to combine columns, such as putting first name and last name together.

Should I manipulate the xml file on the backend to do this in PHP, or is there another way through the js of the jqGrid?

Thanks

07/10/2008
09:11
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

1.Could you please post the code and how xml looks like.

2.Multicolumn sorting is not suported. Instead of this you can put

in index property something like index: 'firstname lastname'

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.

08/10/2008
04:03
Avatar
theosoft
theosoft
Member
Members
Forum Posts: 3
Member Since:
07/10/2008
sp_UserOfflineSmall Offline

I'm not looking to do mutli-column sorting. That's not a requirement.

I would use dojo grid for that.

1. I would like to combine say the first and last names and the address, city, state, zipcodes.  My question was, should I do that on the backend, or is there a way to do it through the javascript.

2. Sorting does not work like this is written. How can I get it to sort?

Here's what the javascript looks like:

jQuery("#list1").jqGrid({
                    url:'method.php?method=TenantList',
                    datatype: "xml",
                    width: 500,
                    height:500,
                    colNames:['Tenant ID','Last Name', 'Address', 'Phone','Email'],
                    colModel:[
                        {name:'TenantID',index:'TenantID', width:55, sorttype:'int'},
                        {name:'sLName',index:'sLName', width:90},
                        {name:'sAddr1',index:'sAddr1', width:100},
                        {name:'sPhone',index:'sPhone', width:80},
                        {name:'sEmail',index:'sEmail', width:80}],
                    rowNum:10,
                    rowList:[10,20,30],
                    imgpath: 'js/jqGrid/themes/basic/images',
                    sortname: 'diffgr:id',
                    viewrecords: true,
                    sortorder: "desc",
                    xmlReader: { root : "NewDataSet", row: "Table", repeatitems: false, id: "TenantID" },
                    caption:"Tenant List"
            });

XML (with data removed since it is live data):

<diffgr:diffgram>

<NewDataSet>

<Table diffgr:id="Table1" msdata:rowOrder="0">
<SiteID></SiteID>
<TenantID></TenantID>
<sLocationCode></sLocationCode>
<sFName></sFName>
<sMI/>
<sLName></sLName>
<sCompany/>
<sAddr1></sAddr1>
<sAddr2/>
<sCity></sCity>
<sRegion></sRegion>
<sPostalCode></sPostalCode>
<sPhone></sPhone>
<sEmail/>
<sMobile/>
<sLicense>002108524</sLicense>
</Table>

</NewDataSet>
</diffgr:diffgram>

08/10/2008
04:39
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

1. Yes, server side

2 When you use local xml file then

set

...

datatype: 'xml',

loadonce: true,

...

Set in colModel the appropriate sorttype properies - ie. int,number,string,date and etc. See docs

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.

08/10/2008
06:38
Avatar
theosoft
theosoft
Member
Members
Forum Posts: 3
Member Since:
07/10/2008
sp_UserOfflineSmall Offline

It seems I've figured it out on the server side.

Let me show you what I've done, in case it can help anyone else.

Sorting seems to be a little funky, but hey, it suits my purposes. Nice grid btw. I've used Rico's grid and Dojo's Grid, but this is the easiest implementation so far.

PHP code:

foreach($xml->NewDataSet->Table as $unit){
            $data[] = array('TenantID'=>$unit->TenantID,
                        'Name'=>$unit->sFName." ".$unit->sLName,
                        'Address'=>$unit->sAddr1."<br />".$unit->sCity.", ".$unit->sRegion."&nbsp; ".$unit->sPostalCode,
                        'sPhone' =>$unit->sPhone,
                        'sEmail' =>$unit->sEmail);
           
        }
       
        $sort['direction'] = $_GET['sord']=='desc' ? 'SORT_DESC' : 'SORT_ASC';
        $sort['field']       = $_GET['sidx'] ? $_GET['sidx'] : 'TenantID';
        $sort['sorttype'] = $_GET['sidx']=='TenantID'?'SORT_NUMERIC':'SORT_STRING';
     
   
  
            /**
            * @desc Build columns using the values, for sorting in php
            */
            $sort_arr = array();
        foreach($data AS $uniqid => $row){
            foreach($row AS $key=>$value){
                $sort_arr[$key][$uniqid] = $value;
            }
        }
        //print_r($data);
        if($sort['direction']){
            array_multisort($sort_arr[$sort['field']], constant($sort['direction']),constant($sort['sorttype']), $data);
        }
        //print_r($data);
        echo "<rows>";
        foreach($data as $key=>$value){
            echo '<row id="'.$value['TenantID'].'">';
                echo '<cell>'.$value['TenantID'].'</cell>';
                echo '<cell>'.$value['Name'].'</cell>';
                echo '<cell><![CDATA['.$value['Address'].']]></cell>';
                echo '<cell>'.$value['sPhone'].'</cell>';
                echo '<cell>'.$value['sEmail'].'</cell>';
            echo '</row>';
        }
        echo "</rows>";

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
74 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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information