title: JqGrid Primary Key other than Id
body: <p>Can any Body tell me how to configure primary key in JqGrid. Since Jqgrid uses id as primary key But I am using fid as primary key.</p>
  
  <p><strong>Example of Jqgrid:</strong></p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" 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;PHP jqGrid&lt;/title&gt;
  
          &lt;link rel="stylesheet" type="text/css" media="screen" href="themes/redmond/jquery-ui-1.8.2.custom.css" /&gt;
          &lt;link rel="stylesheet" type="text/css" media="screen" href="themes/ui.jqgrid.css" /&gt;
  
          &lt;script src="js/jquery-1.5.2.min.js" type="text/javascript"&gt;&lt;/script&gt;
          &lt;script src="js/i18n/grid.locale-en.js" type="text/javascript"&gt;&lt;/script&gt;
          &lt;script src="js/jquery.jqGrid.min.js" type="text/javascript"&gt;&lt;/script&gt;
          &lt;script type="text/javascript"&gt;
              // Here we set a globally the altRows option
              //jQuery.extend(jQuery.jgrid.defaults, { altRows:true });
          &lt;/script&gt;
          &lt;script type="text/javascript"&gt;
  
              jQuery(document).ready(function(){
                  jQuery("#jsonmap").jqGrid({
                      url:'example.php?q=4',
                      datatype: "json",
                      colNames:['FId','Id', 'Colname', 'Index','width','Form Name','Fiel Name','Editable','Show','Extra Field'],
                      colModel:[
                          {name:'fid',index:'fid', width:55,size:10,editable:false},
                          {name:'id',index:'id', width:90,editable:true,size:5}, /*name : database field name*/
                          {name:'col_name',index:'col_name', width:100,editable:true},
                          {name:'ind_ex',index:'ind_ex', width:80, align:"right",editable:true},
                          {name:'width',index:'width', width:80, align:"right",editable:true},
                          {name:'form_name',index:'form_name', width:80, align:"right",editable:true},
                          {name:'field_name',index:'field_name', width:80,align:"right",editable:true},
                          {name:'editable',index:'editable', width:150, sortable:false,editable:true},
                          {name:'s_how',index:'s_how', width:150, sortable:false,editable:true},
                          {name:'extra_field',index:'extra_field', width:150, sortable:false,editable:true}
                   /*{name:'id',index:'id', width:55,editable:false,editoptions:{readonly:true,size:10}},
          {name:'invdate',index:'invdate', width:80,editable:true,editoptions:{size:10}},
          {name:'name',index:'name', width:90,editable:true,editoptions:{size:25}},
          {name:'amount',index:'amount', width:60, align:"right",editable:true,editoptions:{size:10}},
          {name:'tax',index:'tax', width:60, align:"right",editable:true,editoptions:{size:10}},
          {name:'total',index:'total', width:60,align:"right",editable:true,editoptions:{size:10}},
          {name:'closed',index:'closed',width:55,align:'center',editable:true,edittype:"checkbox",editoptions:{value:"Yes:No"}},
          {name:'ship_via',index:'ship_via',width:70, editable: true,edittype:"select",editoptions:{value:"FE:FedEx;TN:TNT"}},
          {name:'note',index:'note', width:100, sortable:false,editable: true,edittype:"textarea", editoptions:{rows:"2",cols:"20"}}
                     */ ],
                      rowNum:10,
                      rowList:[10,20,30],
                      pager: '#pjmap',
                      sortname: 'id',
                      viewrecords: true,
                      sortorder: "desc",
                      gridview: true,
                      editurl:'edit.php',
                      closeAfterEdit: true,
                      closeAfterAdd: true,
                     jsonReader: {
                    //     root: "Rows",
                  //page: "Page",
                  //total: "Total",
                  //records: "Records",
                  repeatitems: false,
                   **fid: "PrimaryKey"**
                          //repeatitems : false,
                          //id: "5"
  
                      },
                      caption: "ADD DELETE UPDATE",
                      height: '100%'
                  }).navGrid('#pager',{edit:false,add:true,del:true,search:false}).navButtonAdd('#pjmap',{
                      caption:"Add",
                      buttonicon:"ui-icon-add",
                      closeAfterAdd:true,
                      onClickButton: function(){
                         jQuery("#jsonmap").editGridRow("new",{height:400,scroll:true,reloadAfterSubmit:false});
                          //alert("Adding Row");
                      },
                      position:"last"
                  })
  
                 /* .navButtonAdd('#pjmap',{
  
                      caption:"Del",
                      buttonicon:"ui-icon-del",
                      onClickButton: function(rp_ge,postdata){
                          alert(getRowData(postdata.id));
  
                      },
                      position:"last"
                  });
                  */
              });
  
  
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;table id="jsonmap"&gt;&lt;/table&gt;
          &lt;div id="pjmap"&gt;&lt;/div&gt;
  &lt;!--&lt;input type="BUTTON" id="bedata" value="Edit Selected" /&gt;--&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  
  server2.php
  &lt;?php
  include_once('../../../../wp-load.php');
  include('dbconfig.php');
  $page = $_GET['page']; // get the requested page 
  $limit = $_GET['rows']; // get how many rows we want to have into the grid 
  $sidx = $_GET['sidx']; // get index row - i.e. user click to sort 
  $sord = $_GET['sord']; // get the direction 
  if(!$sidx) $sidx =1; // connect to the database 
  $result = @mysql_query("SELECT COUNT(*) AS count FROM $table");
  $row = @mysql_fetch_array($result,MYSQL_ASSOC); 
  $count = $row['count'];
  if ( $count &gt;0 ) 
     { $total_pages = ceil($count/1); } 
  else
     { $total_pages = 0; } 
  if ($page &gt; $total_pages) 
    $page=$total_pages;
  $start = $limit*$page - $limit; // do not put $limit*($page - 1) 
  $SQL = "SELECT * from $table Order By id "; 
  $SQL = "SELECT * from $table"; 
  $result = @mysql_query( $SQL ) or die("Couldn t execute query.".mysql_error()); 
  $responce-&gt;page = $page; $responce-&gt;total = $total_pages; $responce-&gt;records = $count; $i=0; 
  while($row = @mysql_fetch_array($result,MYSQL_ASSOC)) 
  { 
  $responce-&gt;rows[$i]['id']=$row[id]; 
  $responce-&gt;rows[$i]['cell']=array($row[id],$row[business_name],$row[title],$row[firstname],$row[lastname],$row[address],$row[city],$row[state],$row[postcode],$row[email]); 
  $i++; 
  } 
  echo json_encode($responce);  
  ?&gt;
  </code></pre>