Forum


17:47

28/12/2009

Hello, I am trying to implement dragging the entire Grid and a dynamic dropdown on my new grid if anyone can point me out in the right direction. I have searched the forums and found that most topics are for dnd which seems to only be for columns and subgrids. And the dropdown option seems to be in asp.net and I don't use that I am using php. Thanks in advance!
Here is my code
<body>
<table id=”s4list” ></table>
<div id=”s4pager”></div>
<script src=”jqgrid/js/search4.js” type=”text/javascript”></script>
</body>
file:search4.js
jQuery(document).ready(
function() {
jQuery(”#s4list”).jqGrid({
url:'jqgrid/search_adv.php?q=1',
datatype: “json”,
width: 500,
colNames:['Store','Business Unit', 'SKU Count', 'Date'],
colModel:[
{name:'Store',index:'store_number', width:65, searchoptions:{sopt:['eq','ne','lt','le','gt','ge']}},
{name:'Businness Unit',index:'bu', width:80, align:”right”,searchoptions:{sopt:['eq','ne','lt','le','gt','ge']}},
{name:'SKU Count',index:'item_count', width:80,align:”right”,searchoptions:{sopt:['eq','ne','lt','le','gt','ge']}},
{name:'Date',index:'datetime', width:90, align:”right”,searchoptions:{sopt:['eq','ne','lt','le','gt','ge']}},
],
rowNum:30,
mtype: “POST”,
rowList:[30,40,60],
pager: '#s4pager',
sortname: 'item_count',
viewrecords: true,
rownumbers: true,
gridview : true,
sortorder: “asc”,
caption:”SKU Count of stores databases”
});
jQuery(”#s4list”).jqGrid('navGrid','#s4pager',
{
edit:false,add:false,del:false,search:true,refresh:true
},
{}, // edit options
{}, // add options
{}, //del options
{multipleSearch:true} // search options
);
jQuery(”#s4list”).jqGrid('gridResize',{minWidth:350,maxWidth:800,minHeight:80, maxHeight:350});
});
PHP > MySQL DB
<?php
include(”dbconfig.php”);
// coment the above lines if php 5
//include(”JSON.php”);
//$json = new Services_JSON();
// end comment
$examp = $_REQUEST["q"]; //query number
$page = $_REQUEST['page']; // get the requested page
$limit = $_REQUEST['rows']; // get how many rows we want to have into the grid
$sidx = $_REQUEST['sidx']; // get index row – i.e. user click to sort
$sord = $_REQUEST['sord']; // get the direction
if(!$sidx) $sidx =1;
$wh = “”;
$searchOn = Strip($_REQUEST['_search']);
if($searchOn=='true') {
$searchstr = Strip($_REQUEST['filters']);
$wh= constructWhere($searchstr);
//echo $wh;
}
function constructWhere($s){
$qwery = “”;
//['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc']
$qopers = array(
'eq'=>” = “,
'ne'=>” <> “,
'lt'=>” < “,
'le'=>” <= “,
'gt'=>” > “,
'ge'=>” >= “,
'bw'=>” LIKE “,
'bn'=>” NOT LIKE “,
'in'=>” IN “,
'ni'=>” NOT IN “,
'ew'=>” LIKE “,
'en'=>” NOT LIKE “,
'cn'=>” LIKE ” ,
'nc'=>” NOT LIKE ” );
if ($s) {
$jsona = json_decode($s,true);
if(is_array($jsona)){
$gopr = $jsona['groupOp'];
$rules = $jsona['rules'];
$i =0;
foreach($rules as $key=>$val) {
$field = $val['field'];
$op = $val['op'];
$v = $val['data'];
if($v && $op) {
$i++;
// ToSql in this case is absolutley needed
$v = ToSql($field,$op,$v);
if ($i == 1) $qwery = ” AND “;
else $qwery .= ” ” .$gopr.” “;
switch ($op) {
// in need other thing
case 'in' :
case 'ni' :
$qwery .= $field.$qopers[$op].” (”.$v.”)”;
break;
default:
$qwery .= $field.$qopers[$op].$v;
}
}
}
}
}
return $qwery;
}
function ToSql ($field, $oper, $val) {
// we need here more advanced checking using the type of the field – i.e. integer, string, float
switch ($field) {
case 'store_number':
case 'bu':
case 'item_count':
return intval($val);
break;
/* case 'datetime':
return floatval($val);
break;*/
default :
//mysql_real_escape_string is better
if($oper=='bw' || $oper=='bn') return “'” . addslashes($val) . “%'”;
else if ($oper=='ew' || $oper=='en') return “'%” . addcslashes($val) . “'”;
else if ($oper=='cn' || $oper=='nc') return “'%” . addslashes($val) . “%'”;
else return “'” . addslashes($val) . “'”;
}
}
//echo $wh;
// connect to the database
$db = mysql_connect($dbhost, $dbuser, $dbpassword)
or die(”Connection Error: ” . mysql_error());
mysql_select_db($database) or die(”Error conecting to db.”);
switch ($examp) {
case 1:
//Mysql Statement to retrieve Counts from a given table. must modify to meet my needs
$result = mysql_query(”SELECT COUNT(*) AS count FROM store_item_monitor WHERE 1 = 1″.$wh);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
if( $count >0 ) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page – $limit; // do not put $limit*($page – 1)
if ($start<0) $start = 0;
//MYSQL Select Statement Needs to be modified to meet my needs
$SQL = “SELECT record, store_number, item_count, bu, datetime FROM store_item_monitor WHERE 1 = 1″.$wh.” ORDER BY “.$sidx.” “.$sord. ” LIMIT “.$start.” , “.$limit;
$result = mysql_query( $SQL ) or die(”Could not execute query.”.mysql_error());
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$responce->rows[$i]['id']=$row[record];
$responce->rows[$i]['cell']=array($row[store_number],$row[bu],$row[item_count],$row[datetime]);
$i++;
}
//echo $json->encode($responce); // coment if php 5
echo json_encode($responce);
break;
case 3:
}
mysql_close($db);
function Strip($value)
{
if(get_magic_quotes_gpc() != 0)
{
if(is_array($value))
if ( array_is_associative($value) )
{
foreach( $value as $k=>$v)
$tmp_val[$k] = stripslashes($v);
$value = $tmp_val;
}
else
for($j = 0; $j < sizeof($value); $j++)
$value[$j] = stripslashes($value[$j]);
else
$value = stripslashes($value);
}
return $value;
}
function array_is_associative ($array)
{
if ( is_array($array) && ! empty($array) )
{
for ( $iterator = count($array) – 1; $iterator; $iterator– )
{
if ( ! array_key_exists($iterator, $array) ) { return true; }
}
return ! array_key_exists(0, $array);
}
return false;
}
?>
18:26

Moderators
30/10/2007

Hello,
If you want to drag the entrie grid you can use jQuery UI dragabble. This can be achieved easy.
You can apply the draggable to the following element - gbox_mygrid - where mygrid is the id of the gird.
The gbox_mygrid is a common div, where all the jqGrid related things are inserted.
About the drop down - if I understand right - just wait for the upcomming jqGrid PHP framework, which will be of beta soon.
This can be done just with 1 line of code.
Best Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
19:27

28/12/2009

Thank you very much
Regarding the resizing, I might be asking for too much but could you hold my hand on how to accomplish this? I tried looking at the 36 demo files and I went through all features on the demo page to see if this was something that was discussed and I was not able to find any already working examples.
Regarding the dynamic dropdown list, yes you did understand correctly. Here is a screen shot of what it would look like
19:34

Moderators
30/10/2007

Hello,
Little confused. What you actually want - resizing or drag and drop?
Reagrds
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
16:37

Moderators
30/10/2007

Hello,
Using jQuery UI with draggable you can
$("#gbox_mygrid").draggable()
Where mygrid is the id of your grid
See the available options for the draggable here
http://jqueryui.com/demos/draggable/
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
52 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.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66