increase the width of jqgrid table - php

I am new in jqgrid and I would like to increase the width of jqgrid.
I have increased the column width but the grid width is not increasing.
I am using php jqgrid.
Is there any parameters to pass this function :=
$grid->renderGrid('#grid','#pager',true, null, null, true,true);
or How can i do this ?
Thanks a lot.

You question is mostly about the commercial version of jqGrid, which I don't know. The main problem exist also in the jqGrid too. jqGrid has width parameter which can be used to define the grid width. I suppose that you should use (or already use) $grid->setGridOptions to define the option. Another option which can be additionally used are autowidth which will be overwrite the width value calculated based on the size of the grid's parent. Other important option can be important you: shrinkToFit which default value is true. It meant that the width properties for the column will be not used as the exact column width in pixel. Instead of that the width properties will be used to define only proportion between the column widths. If the column width of some column should be not changed you should include fixed: true property in the colModel for the corresponding definition of the column. If you want to have exact column width for all columns (as it's defined in width properties of the items of the colModel) you should use the jqGrid setting shrinkToFit: false. Try to include the setting in the $grid->setGridOptions call.

You can use below php code:
// Set grid with 1000px by php
$grid->setGridOptions(array("width"=>1000));
I had same issue, my grid was taking 650px by default with. So, I check some blog and also wiki and now is ended up with :)
Here is my complete php code with auto grid width:
<?php
require_once '../../../jq-config.php';
// include the jqGrid Class
require_once ABSPATH."php/jqGrid.php";
// include the driver class
require_once ABSPATH."php/jqGridPdo.php";
// Connection to the server
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8");
// Create the jqGrid instance
$grid = new jqGridRender($conn);
// SQL query
$sql = <<<SQL
SELECT *,
CASE total_correct_answer
WHEN total_correct_answer=1 THEN 1
WHEN total_correct_answer=2 THEN 3
ELSE 6
END AS points
FROM
(
SELECT COUNT(*) total_correct_answer, v.coupon_code_id, v.coupon_no, v.login_id, v.cc_match_id, v.name, v.contact_no, v.email, v.user_from
FROM (
SELECT p.login_id, ui.name, ui.contact_no,l.email,l.user_from,
p.quiz_id p_quiz_id,p.question_bank_id p_question_bank_id, p.answer_id p_answer_id,
cc.quiz_id cc_quiz_id,cc.question_bank_id cc_question_bank_id, cc.answer_id cc_answer_id,
cc.match_id cc_match_id, p.coupon_code_id, cd.coupon_no
FROM prediction p
INNER JOIN correct_answer cc
INNER JOIN `user_information` ui ON p.`login_id` = ui.`login_id`
INNER JOIN coupon_code cd ON cd.coupon_code_id = p.coupon_code_id
INNER JOIN login l ON l.login_id = p.login_id
WHERE cc.quiz_id=p.quiz_id AND cc.question_bank_id=p.question_bank_id
AND cc.answer_id=p.answer_id AND cc.match_id IN (SELECT match_id FROM `match` WHERE
start_time BETWEEN DATE_ADD(NOW(), INTERVAL -7 DAY) AND NOW())
) v GROUP BY v.coupon_code_id ORDER BY v.login_id DESC
) a
SQL;
// Write the SQL Query
$grid->SelectCommand = $sql;
// Set output format to json
$grid->dataType = 'json';
// Let the grid create the model
$grid->setColModel();
// Set the url from where we obtain the data
$grid->setUrl('grid.php');
// Set alternate background using altRows property
$grid->setGridOptions(array(
"rowNum"=>10,
"sortable"=>true,
"rownumbers"=>true,
"width"=>'auto',
"altRows"=>true,
"multiselect"=>true,
"rowList"=>array(10,20,50),
));
// Change some property of the field(s)
$grid->setColProperty("total_correct_answer", array("label"=>"Answer", "width"=>80));
$grid->setColProperty("coupon_code_id", array("label"=>"Coupon Code", "width"=>80));
$grid->setColProperty("coupon_no", array("label"=>"Coupon Number", "width"=>120));
$grid->setColProperty("login_id", array("label"=>"User ID", "width"=>80));
$grid->setColProperty("cc_match_id", array("label"=>"Match ID", "width"=>80));
$grid->setColProperty("name", array("label"=>"User Name", "width"=>120));
$grid->setColProperty("contact_no", array("label"=>"Contact No", "width"=>120));
$grid->setColProperty("email", array("label"=>"User Email", "width"=>120));
$grid->setColProperty("user_from", array("label"=>"User Mode", "width"=>120));
$grid->setColProperty("points", array("label"=>"User Points", "width"=>120));
// Enable navigator
$grid->navigator = true;
// Enable excel export
$grid->setNavOptions('navigator', array("excel"=>true,"add"=>false,"edit"=>false,"del"=>false,"view"=>false));
// Set different filename
$grid->exportfile = 'Prediction_Report.xls';
// Enjoy
$grid->renderGrid('#grid','#pager',true, null, null, true,true);
$conn = null;
?>

Related

Why does POST Request return 404

I have this code snippet in PHP:
if (strcasecmp($_POST['method'], 'assignId') == 0) {
$username = $_POST['username'];
$response['code'] = 1;
$response['status'] = $api_response_code[$response['code']]['HTTP Response'];
$sql = "CALL new_person('$username')";
if (($result = $conn->query($sql)) === TRUE) {
$row = $result->fetch_assoc();
$response['data'] = $row;
}
deliver_response($response);
new_person is a stored procedure which returns an id, it has been tested and works fine and deliver_response returns JSON format of the input. It has also been tested and works fine.
Why do POST Requests return 404 error?
The stored procedure is being executed, but it doesn't return the result. Finally, when I change the POST method to GET and make a get request instead it works fine!
404 Error means that the page that has to process the post request can't be loaded or not exists. You have to check the php and server logs and maybe you can find a answer to your question.
Prefix everything, especially your variables. The names you are using are used by WordPress internally (see the comment form), so WordPress might try to do something with your form values. If that fails you get an error.
While $_GET problems are usually rather easy to debug, $_POST and $_REQUEST names are not so simple.
The following list is probably not complete. But its bare length tells us a lesson:
Avoid any name you can find in a dictionary. Prefix your form names.
List of reserved names in $_POST and $_REQUEST used by WordPress 3.5
These names might have side effects when used in themes or plugins. Some are used on specific pages only (removeheader), others on multiple pages or requests. Avoid them all if you can.
_ajax_nonce
_page
_per_page
_signup_form
_total
_url
_wp_http_referer
_wp_original_http_referer
_wp_unfiltered_html_comment
_wpnonce
_wpnonce-custom-header-upload
aa
action
action2
active_post_lock
add_new
add_new_users
addmeta
admin_bar_front
admin_color
admin_email
admin_password
admin_password2
ajax
align
allblogs
allusers
alt
approve_parent
approved
attachment
attachment_id
attachments
auth_cookie
author
author_name
autocomplete_type
auto_draft
auto-add-pages
autosave
background-attachment
background-color
background-position-x
background-repeat
banned_email_domains
blog
blog_name
blog_public
blog_upload_space
blogname
bulk_edit
c
calendar
cat
category_base
category_name
catslist
changeit
changes
charset
checkbox
checked
clear-recent-list
closed
comment
comment_approved
comment_author
comment_author_email
comment_author_url
comment_content
comment_date
comment_ID
comment_parent
comment_post_ID
comment_shortcuts
comment_status
comments_listing
comments_popup
confirmdelete
connection_type
content
context
cpage
create-new-attachment
createuser
customize_messenger_channel
customized
customlink-tab
date
date_format
date_format_custom
day
default-header
delete
delete_all
delete_all2
delete_comments
delete_option
delete_tags
delete_widget
deletebookmarks
deletecomment
deleted
deletemeta
deletepost
description
detached
dismiss
display_name
do
edit_date
email
error
exact
excerpt
features
feed
fetch
fheight
file
fileupload_maxk
filter
find_detached
first_comment
first_comment_author
first_comment_url
first_name
first_page
first_post
found_post_id
fwidth
global_terms_enabled
GLOBALS
gmt_offset
guid
height
hh
hidden
hidden_aa
hidden_jj
hidden_mm
hidden_mn
hidden_hh
history
hostname
hour
html-upload
id
ID
ids
id_base
illegal_names
insert-gallery
insertonlybutton
interim-login
item-object
item-type
jj
json
json_data
key
last_name
limited_email_domains
link_id
link_image
link_name
link_rss
link_url
link_visible
linkcheck
locale
locked
log
logged_in_cookie
m
media
media_type
menu
menu_items
menu-item
menu-item-attr-title
menu-item-classes
menu-item-db-id
menu-item-description
menu-item-object
menu-item-object-id
menu-item-parent-id
menu-item-position
menu-item-target
menu-item-title
menu-item-type
menu-item-url
menu-item-xfn
menu-locations
menu-name
message
meta
metakeyinput
metakeyselect
metavalue
minute
mm
mn
mode
monthnum
more
move
multi_number
name
nav-menu-locations
new
new_role
new_slug
new_title
newcat
newcomment_author
newcomment_author_email
newcomment_author_url
newcontent
newuser
nickname
no_placeholder
noapi
noconfirmation
noredir
number
offset
oitar
option
option_page
order
orderby
p
pb
page
page_columns
page_id
page_options
paged
pagegen_timestamp
pagename
parent_id
pass1
pass2
password
permalink_structure
photo_description
photo_src
phperror
ping_status
plugin
plugin_status
pointer
position
post
post_category
post_data
post_format
post_ID
post_id
post_mime_type
post_password
post_status
post_title
post_type
post_view
postid
posts
preview
primary_blog
private_key
ps
public_key
publish
pwd
query
reassign_user
reauth
redirect
redirect_to
ref
referredby
registration
registrationnotification
rememberme
remove-background
removeheader
removewidget
reset-background
resetheader
review
rich_editing
robots
role
s
same
save
savewidget
savewidgets
screen
scrollto
search
second
section
selectall
selection
send
send_password
sentence
short
show_sticky
sidebar
sidebars
signup_for
signup_form_id
site_id
site_name
sitename
size
skip-cropping
spam
spammed
src
ss
stage
start
static
status
sticky
subdomain_install
submit
subpost
subpost_id
super_admin
tab
tag
tag_ID
tag-name
tag_base
tags_input
tax
tax_input
tag-name
target
taxonomy
tb
term
text-color
the-widget-id
theme
theme_status
thumb
timezone_string
time_format
time_format_custom
title
thumbnail_id
trash
trashed
type
undismiss
unspam
unspammed
untrash
untrashed
url
update_home_url
updated
upgrade
upload_filetypes
upload_space_check_disabled
use_ssl
user
user_id
user_login
user_name
username
users
verify-delete
version
visibility
visible
w
weblog_title
welcome_email
welcome_user_email
widget_id
widget_number
widget-id
widget-recent-comments
widget-rss
width
withcomments
withoutcomments
wp_customize
wp_http_referer
wp_screen_options
wp-preview
WPLANG
x1
y1
year
Variable names
$method // Filter: 'user_contactmethods'
$post_type_name . -tab
$sidebar_id . _position
$taxonomy_name . -tab
$whitelist_options // Filter: 'whitelist_options'
__i__ . $something // used in widgets
new . $taxonomy->name
new . $taxonomy->name . _parent
quick-search-posttype- . $post_type_name
quick-search-taxonomy- . $taxonomy_name
widget- . $id_base
Credit : fuxia
Your code starts with if (strcasecmp($_POST['method'], 'assignId') == 0) {
and the if statement is never closed, so your code runs only on post method
I assume deliver_response throw the 404
Please make sure that you have used the "POST" method in the form of the previous page.
Use the flower brackets properly(you have missed one ending flower bracket for first if condition)

filter decimal column in phpGrid

I have a mysql database that includes several fields with decimals.
I'm using phpGrid Lite to display results.
I want users to be able to filter these fields with comparisons ("> 1000"). But all I see for filtering is the text filtering search function. How do I filter results that are numbers, please?
PHP:
$db= new C_DataGrid("SELECT * from `mytable`", "myID", "myDB");
// change default caption
$db-> set_caption("");
// set export type
$db -> enable_export('EXCEL');
//hide primary key column
$db-> set_col_hidden("myID");
$db-> set_col_currency("Salary", "$", "", ",", 0, "0.00");
// enable integrated search
$db-> enable_advanced_search(true);
// set height and weight of datagrid
$db->enable_autowidth(true)->enable_autoheight(true);
// increase pagination size to 30
$db-> set_pagesize(35);
$db->enable_debug(true);
$db-> set_row_color('#dbdbdb', 'silver', '#f0f0f0');
$db-> enable_resize(true);
$db-> display();
You need to set the field property formatter to "integer" manually.
$dg->enable_advanced_search(true);
$dg -> set_col_property("customerNumber",
array("formatter"=>"integer",
"sorttype"=>"integer"));

Make an attendance sheet with jqGrid

I want to make an attendance sheet with jqGrid. I'm using PHP and Mysql
I have two tables, one called MemberInfo and one called Attendance.
From the MemberInfo I want to show in the grid the first name and the last name of the member. Then I want to have a box for every day of the week. I want that when I add some data to those fields, for the data to be saved in the Attendance table and also that if I generate the Attendance grid again, the fields that were already filled up, to show the data.
My question is:
How can I add more columns and How can I connect those columns with the Attendance table? Thanks!
EDIT:
I was able to generate new columns and to add the data to the database with cellEdit. Still having problems with generating the grid with the data from 2 tables. Thanks!
I hope this is clear! if its not please let me know! thanks!
(if there is another library for PHP that would make this easier please let me know)
EDIT:
<?php
require_once 'jqgrid/jq-config.php';
// include the jqGrid Class
require_once "jqgrid/php/jqGrid.php";
// include the driver class
require_once "jqgrid/php/jqGridPdo.php";
// Connection to the server
$conn = new PDO("mysql:host=localhost;dbname=db;","root",NULL);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8");
// Create the jqGrid instance
$grid = new jqGridRender($conn);
// Write the SQL Query
$grid->SelectCommand = 'SELECT member_id, first_name, last_name FROM members_info WHERE member_type !=5';
// set the ouput format to json
$grid->dataType = 'json';
$grid->table ="members_info";
$grid->setPrimaryKeyId("member_id");
// Let the grid create the model
$grid->setColModel();
// Set the url from where we obtain the data
$grid->setUrl('grid.php');
$grid->cacheCount = true;
// Set grid caption using the option caption
$today = date('Y-m-d');
if(isset($_POST['past_month'])){
$today = date('Y-m-d', strtotime($_POST['past_month']));
}
if(isset($_POST['next_month'])){
$today = date('Y-m-d', strtotime($_POST['next_month']));
}
$days = attendance_cal(date('F', strtotime($today)), date('Y', strtotime($today))); // Gets the days for that month and that year
sort($days); //sort the days
foreach($days as $day){
$grid->addCol(array(
"name"=>date('m-d', $day)
));
}
$grid->setGridOptions(array(
"caption"=>"This is custom Caption",
"rowNum"=>30000,
"sortname"=>"member_id",
"hoverrows"=>true,
"width"=>1000,
"height"=>1000,
"cellEdit"=> true,
"cellsubmit"=>"remote",
"cellurl"=> "cell_dump.php",
"rowList"=>array(10,20,50),
"postData"=>array("grid_recs"=>776)
));
// Change some property of the field(s)
$grid->setColProperty("member_id", array("label"=>"ID", "width"=>60, "editable"=>false));
$grid->setColProperty("first_name", array("label"=>"First Name", "width"=>120, "editable"=>false));
$grid->setColProperty("last_name", array("label"=>"Last Name", "width"=>120, "editable"=>false));
// Enjoy
$grid->navigator = false;
// and finaly bind key navigation
// This is way if no events or parameter
//$grid->callGridMethod('#grid', 'bindKeys');
//
//in case of passing events is better this way
$bindkeys =<<<KEYS
$("#grid").jqGrid('bindKeys', {"onEnter":function( rowid ) { alert("You enter a row with id:"+rowid)} } );
KEYS;
$grid->setJSCode($bindkeys);
$grid->renderGrid('#grid','#pager',true, null, null, true,true);
$conn = null;
?>
Let me be more specific:
My table "Members" has the fields "member_id", "first_name", "last_name"
The "Attendance" table has the fields "attendance_id", "member_id", "attendance_date" ,"attendance_value"
My Grid, I want it to look like:
| Member Id | Name | 03-15-2012 | 03-20-2012 | 03-22-2012 |
The "Member Id" column and "Name" column is being generated from the "Members" table with the SelectCommand, the other columns I'm creating them with addCol. I kinda can figure out how to add data to the database via cellEdit, but when I load the sheet, I dont know how to put the data from the database in the grid besides for the ones coming from the Members table. I hope this is clearer! thanks!
I am assuming you have never used jqGrid and you need to get started...
Please have a look at this link, it gives you demos with code for everything you need to know on how to create your grid using PHP.
http://www.trirand.net/demophp.aspx

Conditionally enable or disable delete record button based on the Content of the cell (not just the the id)

I am new to jquery and jqgrid, but i am comfortable with javascript. However I have managed to install jqgrid after some effort.
I have been trying a to find a solution to enable ore disable the delete feature from the navigation bar based on the value of the 'lock' column. I read the following link
jqgrid: how to set toolbar options based on column value in row selected
But I was not able to get the contents of 'lock' cell for the javascript. I also tried to format the lock string without effect.
the jqgrid is loaded via php. The script is here http://www.trirand.net/demophp.aspx
The php script is the following
require_once("JQGrid/jq-config.php");
require_once("JQGrid/php/jqGridASCII.php");
require_once("JQGrid/php/jqGridPdo.php");
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
$grid = new jqGridRender($conn);
$grid->SelectCommand = 'SELECT * FROM `device_assignement` ';
$grid->dataType = 'json';
$grid->setColModel();
$grid->setUrl('Grid_ecu_display.php');
$grid->setColProperty("company",
array("label"=>"Dealer Name",
"width"=>350
),
array( "searchrules"=>
array("searchhidden"=>false, "required"=>false, "search"=>false)));
$grid->setGridOptions(array(
"sortable"=>true,
"rownumbers"=>true,
"rowNum"=>40,
"rowList"=>array(10,50,100),
"sortname"=>"ecu",
"width"=>940,
"height"=>400,
"shrinkToFit"=>true,
"hidden" => true,
"hoverrows"=>true ));
$grid->toolbarfilter = true;
$grid->setFilterOptions(array("stringResult"=>true));
$grid->setColProperty("ecu", array(
"label"=>"ECU Number" ,
"sortable"=>true
));
$grid->setColProperty("lock", array(
"label"=>"<i>Lock</i>" ,
"width"=>60,
"sortable"=>false,
"editable"=>true
));
etc etc...
$ecu = jqGridUtils::GetParam('ecu');
// This command is executed immediatley after edit occur.
$grid->setAfterCrudAction('edit', "UPDATE `ecu_master` SET `lock` = '1' WHERE `ecu` =?",array($ecu));
$grid->navigator = true;
$grid->setNavOptions('navigator', array("pdf"=>true, "add"=>false,"edit"=>true,"del"=>false,"view"=>false, "excel"=>true));
$grid->setColProperty('company',array("searchoptions"=>array("sopt"=>array("cn"))));
$oper = jqGridUtils::GetParam("oper");
if($oper == "pdf") {
$grid->setPdfOptions(array(
// set the page orientation to landscape
"page_orientation"=>"L",
// enable header information
"header"=>true,
// set bigger top margin
"margin_top"=>27,
// set logo image
//"header_logo"=>"logo.gif",
// set logo image width
//"header_logo_width"=>30,
//header title
"header_title"=>"Autograde CMS ECU Allocation List",
// and a header string to print
"header_string"=>"$SoftwareVersion"
));
}
// Run the script
$grid->renderGrid('#grid','#pager',true, null, null, true,true);
This is included in another php script where.
All I want is to enable or disable the delete row button based on the "lock" value
If this seems too basic and ridiculous please let me know I will understand.
If the user click on a cell of the grid the whole row will be selected and the callback function onSelectRow will be called. So you should implement the callback function onSelectRow which has the rowid (the id of the <tr>) as the first parameter. Inside of the onSelectRow handler you can call getCell method. Depend on the value of the 'lock' column (which can be hidden if needed) you can enable of disable "Edit" and "Delete" buttons of the navigator bar.
So the code can be about the following:
$('#list').jqGrid({
... all other jqGrid options which you need
pager: '#pager',
onSelectRow: function (rowid) {
var gridId = $.jgrid.jqID(this.id);
// test 'lock' column for some value like 'yes'
if ($(this).jqGrid('getCell', rowid, 'lock') === 'yes') {
// disable the "Edit" and "Delete" buttons of the navigator
$("#edit_" + gridId).addClass('ui-state-disabled');
$("#del_" + gridId).addClass('ui-state-disabled');
} else {
// enable the "Edit" and "Delete" buttons of the navigator
$("#edit_" + gridId).removeClass('ui-state-disabled');
$("#del_" + gridId).removeClass('ui-state-disabled');
}
}
}).jqGrid('navGrid', '#pager');
Because you are new in jqGrid I want comment the usage of $.jgrid.jqID() function. In the most cases if returns the value of the input parameter: 'list' in case of the example. It's needed for more common case if the id of the grid (the id of the <table> element) contains meta-characters. $.jgrid.jqID() function include additional escape characters (two backslashes: \\) before any meta-character.

set column names my own in jqgrid

I would like to add my own column names in jqgrid and also i want to prevent the column names that is automatically added by jqgrid according to sql query.
I am using this code to do that, but its also getting the name of columns which i have not declare in the method $grid->setColModel(null, null, $mylabels);
Can anyone please tell me what code i should to write for removing extra added column in jqgrid.
require_once '/var/www/html/zbajtmp/public/jqgrid/jq-config.php';
// include the jqGrid Class
require_once "/var/www/html/zbajtmp/public/jqgrid/php/jqGrid.php";
// include the driver class
require_once "/var/www/html/zbajtmp/public/jqgrid/php/jqGridPdo.php";
// Connection to the server
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8");
// Create the jqGrid instance
$grid = new jqGridRender($conn);
// Write the SQL Query
//$grid->SelectCommand = 'SELECT OrderID, OrderDate, CustomerID, Freight, ShipName FROM orders';
$grid->SelectCommand = 'SELECT * FROM clinic';
// set the ouput format to json
$grid->dataType = 'json';
// Let the grid create the model
//$grid->setColModel();
$mylabels = array(
"clinic_name"=>"Clinic ame",
"clinic_address"=>"Address",
"HomePhone"=>"Home Phone",
"WorkPhone"=>"Work Phone",
"Email_Id"=>"Email",
);
// Let the grid create the model with the desired labels
$grid->setColModel(null, null, $mylabels);
// Set the url from where we obtain the data
//$grid->setUrl('/var/www/html/zbajtmp/application/views/scripts/clinic/grid.php');
$grid->setUrl('http://sunlinux/zbajtmp/application/views/scripts/clinic/grid.php');
// Set grid caption using the option caption
$grid->setGridOptions(array(
"caption"=>"This is my custom Caption...",
"rowNum"=>50,
"sortname"=>"id",
"hoverrows"=>true,
"rowList"=>array(20,50,100,1000),
"width"=>"100%",
"height"=>350,
"footerrow"=>true,
"rownumbers"=>true,
"multiselect"=>true,
"altRows"=>true,
"altclass"=>'clsalt',
"loadtext"=>"<div class='loadingbox'>Please wait. Loading...</div>",
));
$grid->renderGrid('#grid','#pager',true, null, null, true,true);
$conn = null;
Thanks a lot.
You need to explicitly select the columns you want - SELECT * wont work
So you need to change :
$grid->SelectCommand = 'SELECT * FROM clinic';
to
$grid->SelectCommand = 'SELECT clinic_name,clinic_address,HomePhone,WorkPhone,Email_Id FROM clinic';

Categories