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
Dynamic colModel
19/08/2008
11:27
Avatar
spacialk
Member
Members
Forum Posts: 4
Member Since:
19/08/2008
sp_UserOfflineSmall Offline

How can I dynamicly load colNames and colModels from a backend? My backend system is php and I want to generate a grid depending on the content that is pushed from my backend.

Thanx

19/08/2008
11:54
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

There are a couple of ways depending on what you want to do.

Declare two variables - one for colNames the other for colModel -

on the server construct these arrays and pass them before constructing the grid.

Also you can construct the whole page with PHP and etc.

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.

19/08/2008
14:31
Avatar
spacialk
Member
Members
Forum Posts: 4
Member Since:
19/08/2008
sp_UserOfflineSmall Offline

Yes but can you change it after the grid is made? Or add some columns dynamicly

20/08/2008
01:29
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Currently this is not possible. If you need some simple you can use hidden columns and the hideCol and showCol methods

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.

20/08/2008
03:02
Avatar
spacialk
Member
Members
Forum Posts: 4
Member Since:
19/08/2008
sp_UserOfflineSmall Offline

Ok I found a sollution. It wasn't that difficult and just to let you all know it does work.

The php end:

function test(){ 
        $test->colnames = array('Id','Rights', 'Username', 'Password', 'First Name', 'Last Name', 'E-Mail');
           $test->colmodel = array("{name:'id',index:'id', editable:false,editoptions:{readonly:true,size:10}}",
           "{name:'role_id',index:'role_id', editable:true,editoptions:{size:25}}",
        "{name:'username',index:'username', editable:true,editoptions:{size:25}}",
        "{name:'password',index:'password', editable:true,editoptions:{size:25}}",
        "{name:'first_name',index:'first_name', editable:true,editoptions:{size:25}}",
        "{name:'last_name',index:'last_name', editable:true,editoptions:{size:25}}",
        "{name:'email',index:'email', editable:true,editoptions:{size:25}}");
        echo json_encode($test);
    }

The javascript end:

$.ajax({
      url: basedir+"users/test",
      dataType: 'json',
      success: function(data){
                    var colnames = data.colnames;
                    var colmodel = data.colmodel;
                    $("#usergrid").jqGrid({       
                           url: 'path',
                           datatype: "json",
                           colNames: colnames,
                           colModel: colmodel,
                           .....
                    });

      }

});

So you can create the full colModel en colNames in the backend, then call it through ajax and then build the grid wih that data.

I hope this is helpfull to anyone.

Kind Regards,

Karel-Jan

20/08/2008
03:18
Avatar
spacialk
Member
Members
Forum Posts: 4
Member Since:
19/08/2008
sp_UserOfflineSmall Offline

Just one more adjustment for the colModel in the php end.

$test->colmodel = array(array('name' => 'id', 'index' => 'id', 'editable' => false , 'editoptions' => array('readonly' => true,'size' => 10)),
           array('name' => 'role_id',        'index' => 'role_id',     'editable' => true,'editoptions' => array('size' => 25)),
        array('name' => 'username',        'index' => 'username',     'editable' => true,'editoptions' => array('size' => 25)),
        array('name' => 'password',        'index' => 'password',     'editable' => true,'editoptions' => array('size' => 25)),
        array('name' => 'first_name',    'index' => 'first_name','editable' => true,'editoptions' => array('size' => 25)),
        array('name' => 'last_name',    'index' => 'last_name', 'editable' => true,'editoptions' => array('size' => 25)),
        array('name' => 'email',        'index' => 'email',     'editable' => true,'editoptions' => array('size' => 25)));

This works fine.

Karel-Jan

20/08/2008
08:46
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Great,

Thanks. Also we can use  GridUnload method and then create again the

grid with new colModel options

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.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
46 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