I am using flexigrid for one of my projects and I need to come up with a way to change the image source depending on the value of one of the cells. For people who are used to flexigrid, I have the following code:
$json .= ",'".addslashes("<span><img src='' id='flag' />" . $row['availability']. "</span>")."'";
and my javascript that I've come up with , looks like this:
<script type="text/javascript">
var available = "<?php echo '$row[availability]' ?>";
if (available == 0) {
document.getElementById('flag').src="images/flag_red.png";
}
elseif (available == 1) {
document.getElementById('flag').src="images/flag_green.png";
}
else {
document.getElementById('flag').src="images/flag_orange.png";
}
I am not sure where I need to insert this function and how to trigger it. Any help will be greatly appreciated.
Regards,
Cristian.
LE: The code where the problem is being reported:
url: 'post2.php',
dataType: 'json',
colModel : [
{display: 'ID', name : 'id', width : 40, sortable : true, align: 'center', hide: true},
{display: 'URL', name : 'url', width : 450, sortable : false, align: 'left'},
{display: 'File Name', name : 'filename', width : 270, sortable : true, align: 'left'},
{display: 'Availability', name : 'availability', width : 50, sortable : true, align: 'center'},
{display: 'State', name : 'state', width : 40, sortable : true, align: 'center'},
{display: 'Total Size', name : 'totalsize', width : 90, sortable : false, align: 'center'},
{display: 'Current Size', name : 'currentsize', width : 90, sortable : false, align: 'center'},
{display: 'Procent', name : 'procent', width : 40, sortable : true, align: 'center'},
{display: 'Log', width : 20, sortable : false, align: 'center'},
],
buttons : [
{name: 'Add', bclass: 'add', onpress : test},
{separator: true},
{name: 'Delete', bclass: 'delete', onpress : test},
{separator: true},
{name: 'Select All', bclass : 'selectall', onpress : test},
{name: 'DeSelect All', bclass : 'deselectall', onpress : test},
{separator: true}
],
searchitems : [
{display: 'URL', name : 'url'},
{display: 'Filename', name : 'filename', isdefault: true}
],
sortname: "state",
sortorder: "asc",
usepager: true,
title: '',
useRp: false,
rp: 5,
showTableToggleBtn: true,
} ----- **IE says there is a problem here** );
});
You shouldn't use javascript for this, you can do it directly in your existing PHP line.
$json .= ",'" .
addslashes("<span><img src='" .
($row['availability'] == 0 ? "images/flag_red.png" :
($row['availability'] == 1 ? "images/flag_green.png" :
"images/flag_orange.png")
) .
"' id='flag' />" . $row['availability'] . "</span>") . "'";
Related
I created a table in my database that has 3 columns on it, the third column is a Download File column that has a text on it that can redirect to a file in my uploads folder. Any ideas on how to create the file download column?
<script type="text/javascript">
var $table = $('#table');
$table.bootstrapTable({
url: 'list-user.php',
search: true,
pagination: true,
buttonsClass: 'primary',
showFooter: true,
minimumCountColumns: 2,
columns: [{
field: 'first',
title: 'Date',
sortable: true,
},{
field: 'last',
title: 'Title',
sortable: true,
}, {
field: 'file',
title: 'Download',
sortable: true,
}],
});
List-user file
<?php
require 'db.php';
$sqltran = mysqli_query($con, "SELECT * FROM user ")or die(mysqli_error($con));
$arrVal = array();
$i=1;
while ($rowList = mysqli_fetch_array($sqltran)) {
$name = array(
'num' => $i,
'first'=> $rowList['fname'],
'last'=> $rowList['lname']
);
array_push($arrVal, $name);
$i++;
}
echo json_encode($arrVal);
mysqli_close($con);
?>
You don't have an array key/value for your file column. Hard to know where you store the filename without seeing your database structure, but replace download_path_column_name with the correct column name.
$name = array(
'num' => $i,
'first'=> $rowList['fname'],
'last'=> $rowList['lname'],
'file' => 'Download'
);
I have a little statistic page where I can summorize my txt messages by user and by country.
I need now to have a new column where i can have operator as well.
To be more accurate, I need column to count all the Vodafone messages. I have already operator in my database and there are 5 different operators. I just need to bring out Vodafone.
Here are json php:
require_once("../corporate/php/modules/core/init.inc.php");
$where = " queue.dt_entered >= '".mysql_real_escape_string(trim($_POST["startdate"]))." 00:00:00' and queue.dt_entered <= '".mysql_real_escape_string(trim($_POST["enddate"]))." 23:59:59' ";
$result = $db -> query("
SELECT queue.user_id AS user, users.username as username, SUM( queue.amount ) AS amount, COUNT( queue.amount ) AS count, IFNULL( (
SELECT TRIM( country )
FROM CORE_E164
WHERE code = SUBSTR( queue.receiver, 3, 3 ) ) , IFNULL( (
SELECT TRIM( country )
FROM CORE_E164
WHERE code = SUBSTR( queue.receiver, 3, 2 ) ) , IFNULL( (
SELECT TRIM( country )
FROM CORE_E164
WHERE code = SUBSTR( queue.receiver, 3, 1 ) ) , 'None'
)
)
) AS country
FROM sms_queue AS queue, users AS users
WHERE queue.user_id = users.id
AND queue.client_type = 'corporative'
AND ".$where."
GROUP BY user, country
order by username
");
$result_array = array();
while ($row = mysql_fetch_array($result)) {
array_push($result_array, array("user" => $row["user"],
"username" => $row["username"],
"country" => $row["country"],
"amount" => $row["amount"],
"count" => $row["count"]
));
}
$result_total = array(
"success"=>true,
"messages" => $result_array
);
echo json_encode($result_total);
I am adding now the html page as well:
function columnWrap(val){
return '<div style="white-space:normal !important;">'+ val +'</div>';
}
var stat_store=new Ext.data.JsonStore({
root: 'messages',
fields : [
{name: 'id', mapping: 'user'},
{name: 'username', mapping: 'username'},
{name: 'country', mapping: 'country'},
{name: 'amount', mapping: 'amount'},
{name: 'count', mapping: 'count'},
{name: 'emt', mapping: 'emt'}
],
proxy : new Ext.data.HttpProxy({url:'group_stats.json.php'})
});
var filters = new Ext.ux.grid.GridFilters({
encode: false,
local: true,
filters: [{
type: 'string',
dataIndex: 'username'
},{
type: 'string',
dataIndex: 'country'
},{
type: 'string',
dataIndex: 'operator'
}]
});
var summary = new Ext.ux.grid.GridSummary();
var stat_grid = new Ext.grid.EditorGridPanel({
store: stat_store,
region: 'center',
plugins: [filters, summary],
columns: [
{header: "User ID", width: 50, dataIndex: 'id', sortable: true},
{header: "Username", width: 160, dataIndex: 'username', sortable: true, filterable: true},
{header: "Target country", width: 330, dataIndex: 'country', sortable: true, filterable: true},
{header: "Request count", width: 110, dataIndex: 'count', sortable: true, filterable: true, summaryType: 'sum'},
{header: "EMT count", width: 110, dataIndex: 'count', sortable: true, filterable: true, summaryType: 'sum'},
{header: "SMS sum", width: 110, dataIndex: 'amount', sortable: true, filterable: true, summaryType: 'sum'}
]
});
var FilterPanel = new Ext.FormPanel({
labelAlign: 'top',
frame:true,
region: 'north',
bodyStyle:'padding:5px 5px 0',
height: 95,
items: [{
layout:'column',
items:[{
columnWidth: 0.1,
layout: 'form',
items: [new Ext.form.DateField({
fieldLabel: 'Alguskuupäev',
name: 'startdate',
id: 'startdate',
value: new Date().format('Y-m-d'),
format:'Y-m-d',
anchor:'95%',
allowBlank:false })]
},{
columnWidth:.1,
layout: 'form',
items: [ new Ext.form.DateField({
fieldLabel: 'Lõppkuupäev',
name: 'enddate',
id: 'enddate',
value: new Date().format('Y-m-d'),
format:'Y-m-d',
anchor:'95%',
allowBlank:false })]
}]
}],
buttons: [{
text: 'Otsi',
handler: function(){
stat_store.baseParams = {startdate: Ext.get('startdate').dom.value, enddate: Ext.get('enddate').dom.value};
stat_store.load({params:{startdate: Ext.get('startdate').dom.value, enddate: Ext.get('enddate').dom.value}});
}
}]
});
var ContentPanel = new Ext.Panel({
layout: 'border',
items : [FilterPanel, stat_grid],
renderTo: 'list',
width: Ext.get('contentdiv').getWidth() - 5,
height: Ext.get('contentdiv').getHeight() - 30
});
Thank you,
Allan
So You want to count number of Vodafone messages among all selected messages.
SELECT ... SUM(IF(queue.operator = 'Vodafone', 1, 0)) AS vodafoners FROM ...
If You have access to some administration of the database (Adminer, phpMyAdmin or something similar), You can add the column in it. If You don't have such access, use SQL query to add the column:
ALTER TABLE yourTable ADD columnName columnType
For example:
ALTER TABLE sms_queue ADD opername VARCHAR(50)
And then use that column in Your SQL query:
... WHERE sms_queue.opername = 'Vodafone'
I also suggest using an index on that column.
I'm using the jQuery plugin Fotorama for my image gallery.
When I click on a thumbnail to open the Fotorama gallery in fullscreen, then it will only open the first time (it will not reopen again after exiting the fullscreen and clicking the same thumbnail).
Here is my code
jQuery code:
$(".open_gallery").click(function (){
$('body').prepend('<div class="close_gallery"> <img src="/images/round_delete.png" width="32" height="32" alt="close"/></div>');
$('.close_gallery').click(function(){
$('.my-fotorama').trigger('fullscreenclose');
$('#foto_gallery').hide();
//window.location.reload();//reload the page
});
$('.my-fotorama').show();
$('.my-fotorama').fotorama({
width: '100%',
height: 'auto',
aspectRatio: 1.4989293362, // =700/467
minWidth: null,
maxWidth: null,
minHeight: null,
maxHeight: null,
transition: 'slide', // or 'fade'
click: true,
loop: false, // or true
autoplay: false,
stopAutoplayOnAction: true,
transitionDuration: 333,
background: '#111',
// 'black', '#b10000', or url(bg.png)
margin: 4,
minPadding: 8,
alwaysPadding: false,
zoomToFit: true,
cropToFit: false,
cropToFitIfFullscreen: false,
flexible: false,
fitToWindowHeight: false,
fitToWindowHeightMargin: 20,
fullscreen: true,
fullscreenIcon: false,
vertical: false,
arrows: true,
arrowsColor: null,
arrowPrev: null,
arrowNext: null,
spinnerColor: '#808080',
nav: 'thumbs', // or 'dots', or 'none'
navPosition: 'auto',
// 'top' | 'right' | 'bottom' || 'left'
navBackground: null,
dotColor: null,
thumbSize: null, // 36 or 51, whatever :-)
thumbMargin: 4,
thumbBorderWidth: 2,
thumbBorderColor: null,
// 'white', '#ff9', or even '#00ff84 #00eb89 #00b66f'
thumbsCentered: true,
hideNavIfFullscreen: false,
caption: 'overlay', // 'simple', or 'none'
preload: 3,
preloader: 'dark', // or 'white'
shadows: true,
data: null,
// e.g. [{img: 'http://fotoramajs.com/;-)/03.jpg'}, {img: 'broken.jpg'}, {img: 'http://fotoramajs.com/;-)/13.jpg'}]
html: null,
hash: false,
startImg: 0,
cssTransitions: true,
onShowImg: null,
// function(data){alert('Photo #'+(data.index+1)+' is coming!')},
onClick: null,
onFullscreenOpen: null,
onFullscreenClose: function(data){
$('#foto_gallery').hide();
$('.close_gallery').hide();
},
onTransitionStop: null
});
});
Thumbnails
<div class="photo-section">
<table>
<td>
<a class="open_gallery" href="#"> <img border="0" src="<?=$arItem["PICTURE"]["SRC"]?>" width="140px" height="110px" alt="<?=$arItem["NAME"]?>" title="<?=$arItem["NAME"]?>" />
</a>
</td>
</table>
Main images
<div id="foto_gallery">
<div class="my-fotorama">
<img src="<?=$arItem["PREVIEW_PICTURE"]["SRC"]?>">
</div>
Never worked with Fotorama, but I noticed that you are hiding the #foto_gallery div after clicking the close button. But you are not showing it on the open event, so maybe the hide is the problem.
When you use the hide(); method, then jQuery sets the CSS of that object to display: none;, now if the plugin is animating the CSS property opacity to 1, then it will not be visible in the browser because of the display: none;.
Update
I looked at your code again and you initilize the FotoRama gallery on the .my-fotorama element every time the click event is triggered. Move the whole block code of $('.my-fotorama').fotorama({.. above the click function and use the plugins method for closing and opening the fullscreen mode. I updated your code to this:
// triggers when the DOM is loaded
$(function() {
$('.my-fotorama').fotorama({
width: '100%',
height: 'auto',
aspectRatio: 1.4989293362, // =700/467
minWidth: null,
maxWidth: null,
minHeight: null,
maxHeight: null,
transition: 'slide', // or 'fade'
click: true,
loop: false, // or true
autoplay: false,
stopAutoplayOnAction: true,
transitionDuration: 333,
background: '#111',
// 'black', '#b10000', or url(bg.png)
margin: 4,
minPadding: 8,
alwaysPadding: false,
zoomToFit: true,
cropToFit: false,
cropToFitIfFullscreen: false,
flexible: false,
fitToWindowHeight: false,
fitToWindowHeightMargin: 20,
fullscreen: true,
fullscreenIcon: false,
vertical: false,
arrows: true,
arrowsColor: null,
arrowPrev: null,
arrowNext: null,
spinnerColor: '#808080',
nav: 'thumbs', // or 'dots', or 'none'
navPosition: 'auto',
// 'top' | 'right' | 'bottom' || 'left'
navBackground: null,
dotColor: null,
thumbSize: null, // 36 or 51, whatever :-)
thumbMargin: 4,
thumbBorderWidth: 2,
thumbBorderColor: null,
// 'white', '#ff9', or even '#00ff84 #00eb89 #00b66f'
thumbsCentered: true,
hideNavIfFullscreen: false,
caption: 'overlay', // 'simple', or 'none'
preload: 3,
preloader: 'dark', // or 'white'
shadows: true,
data: null,
html: null,
hash: false,
startImg: 0,
cssTransitions: true,
onShowImg: null,
onClick: null,
onFullscreenOpen: function() {
$('#foto_gallery, .my-fotorama').show();
},
onFullscreenClose: function(data){
$('#foto_gallery, .my-fotorama').hide();
$('.close_gallery').remove(); // you need to remove the close element, otherwise it will add and add one every time the click event is triggered.
},
onTransitionStop: null
});
// add the click event to all open_gallery classes in the DOM
$(".open_gallery").click(function () {
$('body').prepend('<div class="close_gallery"> <img src="/images/round_delete.png" width="32" height="32" alt="close"/></div>');
$('.close_gallery').click(function() {
$('.my-fotorama').trigger('fullscreenclose');
});
$('.my-fotorama').trigger('fullscreenopen');
});
});
I have this menu:
items:[
{
xtype: 'form',
id: 'searchPanel',
title: 'Search',
collapsible: true,
bodyPadding: 10,
height: 210,
buttonAlign: 'left',
defaults: {
width: 400,
labelWidth: 120,
allowBlank: true,
enableKeyEvents: true
},
layout: {
type: 'table',
columns: 2
},
items: [
{
xtype: 'textfield',
name: 'txtFltrSiteName',
fieldLabel: 'Site name or alias',
id: 'txtFltrSiteName'
},
{
xtype: 'textfield',
name: 'txtDiskCost',
fieldLabel: 'Disk cost',
id: 'txtDiskCost',
style: 'margin-left: 100px;'
},
{
xtype: 'textfield',
name: 'txtFltrProjectName',
fieldLabel: 'Project name',
id: 'txtFltrProjectName'
},
// many other fields
And chackboxes and text fields have diffirent width, so it looks ugly.
So the queston is:
How to make empty <td> in this form?
For examle I want 6-2 items:
----------
| 1 | 1 |
| 2 | 2 |
| 3 | |
| 4 | |
|..etc...|
----------
Just make hidden input.
like this:
{
xtype: 'hidden',
name: 'hidden1',
id: 'hidden1'
},
This will make <td> column, but it'll be empty coz it'll be hidden input in it.
Here's a better one:
{
xtype : 'label',
text : '',
labelSeparator: ''
}
I'm sure it can be done, I just need to see some examples. I want to use flexigrid to show massive sets of data stored in mysql. I am proficient in php, but new to jquery and json.
Can anyone point me in the right direction or provide a good example? I need to see how to return data back to the flexigrid json.
Thank you
Great Tutorial on this topic
This is just the partial code for returning your database results, you would call you page with the flexigrid jquery code
while ($row = mysql_fetch_assoc($results)) {
$data['rows'][] = array(
'id' => $row['pf_id'],
'cell' => array(
$row['cat_code'],
$row['cat_title'],
$row['cat_link'] = "Edit | Associate Familys | Order Children")); }
echo json_encode($data);
call the page with the flexigrid jquery code
$("#flex1").flexigrid({
url: 'category_main_json.php',
dataType: 'json',
colModel : [
{display: 'Code', name : 'cat_code', width : 70, sortable : true, align: 'left'},
{display: 'Name', name : 'cat_title', width : 550, sortable : true, align: 'left'},
{display: 'Action', name : 'cat_link', width : 205, sortable : true, align: 'left'},
],
buttons : [
{name: 'Add New Category', bclass: 'add', onpress : test},
{separator: true}
],
searchitems : [
{display: 'Code', name : 'cat_code'},
{display: 'Name', name : 'cat_title', isdefault: true}
],
sortname: "cat_code",
sortorder: "asc",
usepager: true,
useRp: true,
rp: 50,
showTableToggleBtn: false,
resizable: false,
width: 880,
height: 450,
singleSelect: true,
showTableToggleBtn: false
}
);