Welcome Guest, Not a member yet? Register   Sign In
jqgrid problem
#1

[eluser]Unknown[/eluser]
<?php
class Jqgrid extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper(array('url'));
}
function index()
{
$this->load->view('jqgrid/home');
}
function example(){
$page = isset($_POST['page'])?$_POST['page']:1; // get the requested page
$limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid
$sidx = isset($_POST['sidx'])?$_POST['sidx']:'invid'; // get index row - i.e. user click to sort
$sord = isset($_POST['sord'])?$_POST['sord']:''; // get the direction

if(!$sidx) $sidx =1;
$db = mysql_connect('localhost', 'root', 'root') or die("Connection Error: " . mysql_error());
mysql_select_db('sampledb') or die("Error connecting to db.");
$result = mysql_query("SELECT COUNT(*) AS count FROM invheader");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
if( $count > 0 && $limit > 0) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}

if ($page > $total_pages) $page=$total_pages;

$start = $limit*$page - $limit;
if($start <0) $start = 0;

// the actual query for the grid data
$SQL = "SELECT * FROM invheader";
$result = mysql_query( $SQL ) or die("Couldn't execute query.".mysql_error());

// we should set the appropriate header information. Do not forget this.

header("Content-type: text/xml;charset=utf-8");

$s = "&lt;?xml version='1.0' encoding='utf-8'?&gt;";
$s .= "<rows>";
$s .= "<page>".$page."</page>";
$s .= "<total>".$total_pages."</total>";
$s .= "<records>".$count."</records>";

// be sure to put text data in CDATA
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$s .= "<row id='". $row['invid']."'>";
$s .= "<cell>". $row['invid']."</cell>";
$s .= "<cell>". $row['invdate']."</cell>";
$s .= "<cell>". $row['amount']."</cell>";
$s .= "<cell>". $row['tax']."</cell>";
$s .= "<cell>". $row['total']."</cell>";
$s .= "<cell>&lt;![CDATA[". $row['note']."]]></cell>";
$s .= "</row>";
}
$s .= "</rows>";

echo $s;
}
}
?&gt;
-------------------------------------------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html xml:lang="en" lang="en"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;My First Grid&lt;/title&gt;

&lt;link rel="stylesheet" type="text/css" media="screen" href="&lt;?php echo base_url()?&gt;asset/jqgrid/css/ui-lightness/jquery-ui-1.7.3.custom.css" /&gt;
&lt;link rel="stylesheet" type="text/css" media="screen" href="&lt;?php echo base_url()?&gt;asset/jqgrid/css/ui.jqgrid.css" /&gt;

[removed][removed]
[removed][removed]
[removed][removed]

[removed]
$(function(){
$("#list").jqGrid({
url:'&lt;?php echo base_url("");?&gt;',
datatype: 'xml',
mtype: 'post',
colNames:['Inv No','Date', 'Amount','Tax','Total','Notes'],
colModel :[
{name:'invid', index:'invid', width:20},
{name:'invdate', index:'invdate', width:90, align:'center',editable:true, formatter:'date',editrules: { required: true, date:true}, formatoptions:{srcformat:'Y-m-d', newformat:'m/d/Y'}},
{name:'amount', index:'amount', width:80, align:'center',editable:true,edittype:'text'},
{name:'tax', index:'tax', width:80, align:'center',editable:true,edittype:'text'},
{name:'total', index:'total', width:80, align:'center',editable:true, edittype:'text'},
{name:'note', index:'note', width:150, align:'center', sortable:false,editable:true,edittype:'text'}
],
pager: '#gridpager',
width: 600,
height: 300,
rowNum:10,
rowList:[10,20,30],
sortname: 'invid',
sortorder: 'desc',
viewrecords: true,
gridview: true,
caption: 'Clientes'
}).navGrid('#gridpager',{view:true,edit:true,add:true,del:true,search:true},
{closeAfterEdit:true,modal:true}, // use default settings for edit
{}, // use default settings for add
{}, // delete instead that del:false we need this
{}, // enable the advanced searching
{closeOnEscape:true} /* allow the view dialog to be closed when user press ESC key*/
);
});
[removed]
&lt;/head&gt;
&lt;body&gt;
<table id="list"><tr><td/></tr></table>
<div id="gridpager"></div>
&lt;/body&gt;
&lt;/html&gt;

------
#2

[eluser]djupond[/eluser]
what's your problem ?!
#3

[eluser]Ayeyermaw[/eluser]
And put some forum "[ code ][ /code ]" wrappers around your pasted code please. We can't read it very well otherwise

eg.

Code:
&lt;?php
  class Jqgrid extends CI_Controller {
        function __construct()
        {
        parent::__construct();
              $this->load->helper(array(‘url’));
        }
        function index()
        {
              $this->load->view(‘jqgrid/home’);
        }




Theme © iAndrew 2016 - Forum software by © MyBB