Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 922263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:00:05+00:00 2026-05-15T19:00:05+00:00

I am trying to implement jqgrid v3.7 in my webapplication created using cakephp v1.3.

  • 0

I am trying to implement jqgrid v3.7 in my webapplication created using cakephp v1.3.

My controller code is as follows

function admin_index()
{
    // get how many rows we want to have into the grid - rowNum parameter in the grid
    $limit = $this->params['url']['rows'];

    // get index row - i.e. user click to sort. At first time sortname parameter -
    // after that the index from colModel
    $sidx = $this->params['url']['sidx'];

    // sorting order - at first time sortorder
    $sord = $this->params['url']['sord'];

    // if we not pass at first time index use the first column for the index or what you want
    if( !$sidx ) $sidx = 1;

    // calculate the number of rows for the query. We need this for paging the result
    $row = $this->Constituency->find('count');
    $count = $row;

    // calculate the total pages for the query
    if( $count > 0 )
    {
        $total_pages = ceil($count / $limit);
    }
    else
    {
        $total_pages = 0;
    }

    // if for some reasons the requested page is greater than the total
    // set the requested page to total page
    if( $page > $total_pages ) $page = $total_pages;

    // calculate the starting position of the rows
    $start = $limit * $page - $limit;

    // if for some reasons start position is negative set it to 0
    // typical case is that the user type 0 for the requested page
    if( $start < 0 ) $start = 0;

    // the actual query for the grid data
    $limit_range = $start . "," . $limit;
    $sort_range = $sidx . " " . $sord;
    //$result = $this->Constituency->findAll(null, "id,name", $sort_range, $limit_range, 1, null);
    $this->Constituency->recursive = -1;
    $result = $this->Constituency->find('all', array(
        'fields' => array('id', 'name'),
        'order' => $sidx,
        'limit' => $start .",". $limit_range
    ));

    $i=0;
    $response->page = $page;
    $response->total = $total_pages;
    $response->records = $count;

    foreach($result as $result)
    {
        $response->rows[$i]['id'] = $result['Constituency']['id'];
        $responce->rows[$i]['cell']=array($result['Constituency']['id'],$result['Constituency']['name']);
        $i++;
    }

    echo json_encode($response);
}

the view file contains the following code

$this->Html->css('ui.jqgrid');
$this->Html->script('jquery.jqGrid.min');

<script type="text/javascript">
    $(document).ready(function(){
        $("#list").jqGrid(
        {
            url:'<?php echo $this->Html->url(array("controller" => "constituencies", "action" => "index")); ?>',
            datatype: "json",
            colNames:['Id','Name'],
            colModel:[
                {name:'id',index:'id', width:55},
                {name:'name',index:'name', width:90},
            ],
            rowNum:10,
            rowList:[10,20,30],
            pager: jQuery('#pager'),
            sortname: 'id',
            viewrecords: true,
            sortorder: "desc",
            caption:"Constituencies"
        });
        $("#list").navGrid("#pager",{edit:false,add:false,del:false});
    })
</script>

<div class="constituencies index">
    <h2><?php __('Constituencies'); ?></h2>
    <table id="list"  class="scroll"></table>
    <div id="pager"  class="scroll" ></div>
</div>

Now when I load the index action I get a lot of errors

Undefined index: rows
Undefined index: sidx
Undefined index: sord
etc. etc.

Has anybody included jqgrid in a cakephp based application ?

How do I include the jqgrid in my application ?
Please help me do this.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:00:06+00:00Added an answer on May 15, 2026 at 7:00 pm

    There was some incorrect values assigned in the find function for constituency model.

    here is the correct complete working code:

    THIS IS THE CONTROLLER CODE:

    1.) Leave the function in which the grid is shown a blank like this

    function index()
    {
    
    }
    

    2.) Then create a new function for showing the grid with data like this :

    function admin_showGrid()
    {
        $this->autoRender = false;
    
        // get how many rows we want to have into the grid - rowNum parameter in the grid
        $limit = $this->params['url']['rows'];
    
        // get index row - i.e. user click to sort. At first time sortname parameter -
        // after that the index from colModel
        $sidx = $this->params['url']['sidx'];
    
        // sorting order - at first time sortorder
        $sord = $this->params['url']['sord'];
    
        $page = $this->params['url']['page'];
    
        // if we not pass at first time index use the first column for the index or what you want
        if( !$sidx ) $sidx = 1;
    
        // calculate the number of rows for the query. We need this for paging the result
        $row = $this->{Model_Name}->find('count');
        $count = $row;
    
        // calculate the total pages for the query
        if( $count > 0 )
        {
            $total_pages = ceil($count / $limit);
        }
        else
        {
            $total_pages = 0;
        }
    
        // if for some reasons the requested page is greater than the total
        // set the requested page to total page
        if( $page > $total_pages ) $page = $total_pages;
    
        // calculate the starting position of the rows
        $start = $limit * $page - $limit;
    
        // if for some reasons start position is negative set it to 0
        // typical case is that the user type 0 for the requested page
        if( $start < 0 ) $start = 0;
    
        // the actual query for the grid data
        $limit_range = $start . "," . $limit;
        $sort_range = $sidx . " " . $sord;
        //$result = $this->{Model_Name}->findAll(null, "id,name", $sort_range, $limit_range, 1, null);
        $this->{Model_Name}->recursive = -1;
        $result = $this->{Model_Name}->find('all', array(
            'fields' => array('id', 'name'),
            'order' => $sort_range,
            'limit' => $limit_range
        ));
    
        $i = 0;
        $response->page = $page;
        $response->total = $total_pages;
        $response->records = $count;
    
        foreach($result as $result)
        {
            $response->rows[$i]['id'] = $result['{Model_Name}']['id'];
            $response->rows[$i]['cell'] = array($result['{Model_Name}']['id'], $result['{Model_Name}']['name']);
            $i++;
        }
    
        echo json_encode($response);
    
        //writing exit() is necessary.
        exit();
    }
    

    THIS IS THE VIEW CODE:

    1.) include the necessary files

    echo $this->Html->css('ui.jqgrid');
    
    echo $this->Html->script('grid.locale-en');
    echo $this->Html->script('jquery.jqGrid.min');
    

    2.) add the following javascript code in your VIEW file

    <script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery("#list").jqGrid(
        /* '#list' is the ID of the table in which you want populated results */
        {
            url:'<?php echo $this->Html->url(array("controller" => "{Controller_Name}", "action" => "{Action_Name}")); ?>',
            datatype: "json",
            mtype: "GET",
            colNames:['Id','Name'],
            colModel:[
                {name:'id',index:'id', width:55},
                {name:'name',index:'name', width:90},
            ],
            rowNum:10,
            rowList:[10,20,30],
            pager: jQuery('#pager'), /* id of the pagination element */
            sortname: 'id',
            viewrecords: true,
            sortorder: "asc",
            caption:"Enter table Heading or the name you want to show for the table",
            height:"auto",
            autowidth: true
        });
        jQuery("#list").navGrid("#pager",{edit:false,add:false,del:false});
    })
    </script>
    

    3.) And finally the HTML in the same view file

    <table id="list" style="height:auto;"></table>
    <div id="pager"></div>
    

    If you still face any problems with the code above let me know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 523k
  • Answers 523k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This will never work, because timers retain their target, which… May 16, 2026 at 9:37 pm
  • Editorial Team
    Editorial Team added an answer In the few clients I tried, this is all that… May 16, 2026 at 9:37 pm
  • Editorial Team
    Editorial Team added an answer I'm developing a time tracking app without timers called Lapsus.… May 16, 2026 at 9:37 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to implement a simple function using jqGrid, but it doesn't seem to
Has anyone been able to implement the JQuery grid plugin, jqGrid? I'm trying to
I've been trying to implement jQuery's grid function in my Asp.Net MVC app. I'm
Im trying to implement fade in effect to my mp3 player. I´m using FloatControl
I am trying to implement this function which works everywhere except every IE version
I have just started with jQuery. I am trying to implement zebra striping in
I am trying to add a custom button to a JqGrid that implements a
All I am currently trying implement something along the lines of dim l_stuff as
Trying to implement the following behavior on an iPad. I have a map-centric application
Im trying to implement a single aspx page with several externals dll's. Following Zimmergren's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.