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
Accesing jqgrid columns and values
09/12/2010
16:20
Avatar
funandlearning
Member
Members
Forum Posts: 9
Member Since:
10/10/2010
sp_UserOfflineSmall Offline

Hi All -

I have been playing around with jqgrid, and have the following question.

  • To get the values of ID column, we use getDataIDs(). Is there a way I can get the values of other columns (I am using custom formatter to create a column link and adding delete link to each row on 'loadComplete'.)
  • Can I use conditional statements while looping over a column and values. I mean, I want to loop over user_name column below and depending on its values I want to show delete for some values and do not want to display for some values

below is the code.

$(document).ready(function() {


   $("#list").jqGrid(
   {
    url:'index.cfc?method=getData', //CFC that will return the users
    datatype: 'json', //We specify that the datatype we will be using will be JSON
    mtype: 'POST',
    colNames:['User ID', 'User Name'], //Column Names
    colModel :[    
     {name:'user_id',index:'user_id', sorttype:"string", formatter: 'showlink', formatoptions:{baseLinkUrl:'#'}},
     {name:'user_name',index:'user_name', sorttype:"string"},
     {name:'act',index:'act',sortable:false}
    ],
    pager: $('#pager'), //The div we have specified, tells jqGrid where to put the pager
    toppager: true,
    height: 'auto',
    width: 1270,
    rowNum:25, //Number of records we want to show per page
    rowList:[25,50,100], //Row List, to allow user to select how many rows they want to see per page
    sortorder: "asc", //Default sort order
    sortname: "user_id", //Default sort column
    loadComplete: function() {
     var myGrid = $("#list");
     var ids = myGrid.getDataIDs();
     for (var i = 0, idCount = ids.length; i < idCount; i++) {
      $("#"+ids[i]+" a",myGrid[0]).click(function(e) {
       var hash=e.currentTarget.hash;// string like "#?id=0"
       if (hash.substring(0,5) === '#?id=') {
        var id = hash.substring(5,hash.length);
        var text = this.textContent;
        alert("clicked the row with id='"+id+"'. Link contain '"+text+"'");
        location.href="http://en.wikipedia.org/wiki/"+text;

       }
       e.preventDefault();

      });
     }  

     for(var i=0;i<ids.length;i++){
      var cl = ids[i];

       vdelete = "<a href='#' onclick=\"testfn('"+cl+"')\">Delete</a></ids>";  
       jQuery("#list").setRowData(ids[i],{act:vdelete})
     }    
    },
    caption: '', //Grid Name
    jsonReader: {
    root: "ROWS", //our data
    page: "PAGE", //current page
    total: "TOTAL", //total pages
    records:"RECORDS", //total records
    cell: "",
    id: "0"

    }
   })


   $("#list").jqGrid('navGrid','#pager',
   {
    edit:false,
    add:false,
    del:false,
    search:true,
    refresh: true,
    searchtext:"Search",
    refreshtext: "Refresh",
    'cloneToTop':true
   });


  });

Thanks

16/12/2010
16:35
Avatar
rmvenancio
Portugal
Member
Members
Forum Posts: 12
Member Since:
09/11/2010
sp_UserOfflineSmall Offline

var id = jQuery("#list").jqGrid('getGridParam', 'selrow'); // return the id

// To return other fields values :
    if (id) {
      var ret = jQuery("#list").jqGrid('getRowData', id);
      return ret.OtherFieldName;      
    }

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

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

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

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information