John Davidson

Is it possible to pass colModel to jQgrid from php backend?

0 comments
Message:


Am trying to build a dynamic table. Where the backend holds the colModel and the table data.


For example:


colModel:[
{
name:'Forename',
index:'forename',
align: 'left'
},
{
name:'Surname',
index:'surname'
},
{
name:'Date Of Birth',
index:'dob',
width: 80
}
]

is on the front end but wanna be able to construct it via PHP.



My Answer:
Yes, it is possible to pass colModel to jQgrid from a PHP backend. You can generate the colModel array in PHP and then pass it to the frontend as a JSON object. Here is an example of how you can do this:

In your PHP backend, you can generate the colModel array like this:

php
$colModel = array(
array(
'name' => 'Forename',
'index' => 'forename',
'align' => 'left'
),
array(
'name' => 'Surname',
'index' => 'surname'
),
array(
'name' => 'Date Of Birth',
'index' => 'dob',
'width' => 80
)
);

echo json_encode($colModel);


Then, in your frontend, you can make an AJAX request to fetch the colModel array from the PHP backend and use it to initialize the jQgrid:

javascript
$.ajax({
url: 'your_php_backend_url.php',
dataType: 'json',
success: function(data) {
$('#your_grid_id').jqGrid({
colModel: data,
// other jQgrid options
});
}
});


This way, you can dynamically generate the colModel array in PHP and pass it to the frontend for use in jQgrid.

Rate this post

3 of 5 based on 5603 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us