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_Related Related Topics sp_TopicIcon
Dynamic colNames and ColModel
27/11/2012
14:59
Avatar
luismartin
New Member
Members
Forum Posts: 2
Member Since:
27/11/2012
sp_UserOfflineSmall Offline

Hello, I'm new to this jquery plugin. I decided to use it among many others because this one looks the most

powerful. However I'm having problems to get it working.

First of all, as said in the topic, since the content will be served from the server (PHP), and I want to use it to

display different lists of items, I need that both properties colNames and colModel will be served dynamically.

So, this is how I set it up in a js file:

$(document).ready(function() {
    $("#listing").jqGrid({
    	datatype: "clientSide",
    	height: 500,
        colNames: namesList,
        colModel: modelList,
       	multiselect: true,
        viewrecords: true,
       	caption: "Test"
    });
});

Here's an example in PHP of an item type whose records must be listed. I set its corresponding column

names and how will they be displayed:

$colNames = array('Id', 'Title', 'Featured', 'Language', 'Date created', 'Date modified', 
'Date published', 'Status');
        $colModel = array(
            array('name' => 'id_article', 'id' => 'id_article', 'width' => 60, 'sorttype' => 'int'),
            array('name' => 'title', 'id' => 'title', 'width' => 450, 'sorttype' => 'text'),
            array('name' => 'featured', 'id' => 'featured', 'width' => 60, 'sorttype' => 'int'),
            array('name' => 'language', 'id' => 'language', 'width' => 60, 'sorttype' => 'text'),
            array('name' => 'date_c', 'id' => 'date_c', 'width' => 120, 'sorttype' => 'date'),
            array('name' => 'date_m', 'id' => 'date_m', 'width' => 120, 'sorttype' => 'date'),
            array('name' => 'date_p', 'id' => 'date_p', 'width' => 120, 'sorttype' => 'date'),
            array('name' => 'status', 'id' => 'status', 'width' => 60, 'sorttype' => 'int')
        );

This is how I dynamically create the variables I need for colNames, colModel and the data to display

(enclosed with script tags):

var namesList = < ?php echo json_encode($colNames)  ? >, 
    modelList = < ?php echo json_encode($colModel)  ? >, 
    data = < ?php echo json_encode($lista)  ? > 
    
for(var i = 0; i <= datos.length; i++) {
    $('#listing').addRowData(i+1, data[i]);
}

With this all configured, I just get to build the background of the grid with the column names.

No data is displayed. Could you please help me?

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

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