jquery combine two mysql values - php

I use jquery (JQwidgets)to display values in a grid. I have a database with multiple columns and lets say i have in column A the value "http://www.google.com" and in column B the value "Google".
What i want is to display "Google" in the grid and when people click on it it opens the url.
Right now i have this code wich gets the variables from the database.
var source =
{
datatype: "json",
datafields: [
{ name: 'sitename', type: 'string'},
{ name: 'url', type: 'string'},
],
url: 'http://www.site.com/data.php',
cache: false
};
After that the values are displayed using this...
$("#jqxgrid").jqxGrid(
{
pagesize : 25,
pagesizeoptions: ['25', '50', '100'],
width : 1170,
theme:"black",
source: dataAdapter,
pageable: true,
autoheight: true,
selectionmode: 'multiplecellsextended',
columns: [
{ text: 'Website', datafield: 'website' , width: 700, cellsrenderer: linkrenderer},
]
});
So what i cannot get to work is to combine the two values. What i tried is this...
var website = function (row, datafield, value) {
return 'sitename' + 'url';
}

You haven't set a linkrenderer function.
Above it, add
var linkrenderer = function(row, column, value, defaultHtml, columnSettings, rowData) {
return '<a href="' + rowData.url + '">' + value + '</div>';
}
The last column rowData is a JSON object of everything already rendered, so maybe add the columns
columns: [{text: 'URL', datafield: 'url' , width: 100}, {text: 'Website', datafield: 'sitename' , width: 700, cellsrenderer: linkrenderer}]
Hiding the URL column
$("#jqxgrid").jqxGrid('hidecolumn', 'url');

Related

jqgrid using local data only displays one row

I'm having trouble with a search results page. The search page has 16 inputs and the results page uses a dynamic query to fetch the results and input them into an array which is used (with json_encode) to populate a jqgrid with the results. However, the grid is only displaying the first record. I've added a php "echo
json_encode()..." script to the page to view the json formatted results and it's showing all the records in the search results, so I don't know why the grid is only displaying the first row. I'd appreciate any help I can get on this. Here is the script for the grid (I'm not including the dynamic query or the array scripts because they're working fine):
$(document).ready(function () {
$("#slist").jqGrid({
data: "srchres",
datatype: "local",
mtype: "GET",
colNames: ['ProjectID', 'Customer Name', 'Invoice Number', 'Vehicle Info.', 'Project Date'],
colModel: [
{name:'ProjectID', index:'ProjectID', align:'right', hidden:true, editable:false},
{name:'CustomerName', index:'CustomerName', editable:false, width:175, align:'center'},
{name:'InvoiceNumber', index:'InvoiceNumber', editable:false, width:175, align:'center'},
{name:'VehicleInfo', index:'VehicleInfo', width:350, align:'left', editable:false},
{name:'ProjectDate', index:'ProjectDate', editable:false, width:125, align:'center', formatter: 'date', formatoptions: { newformat: 'm/d/Y' }},
],
jsonReader: {repeatitems: false, id: "ProjectID"},
onSelectRow: function (rowid) {
var rowData = $(this).getRowData(rowid);
document.location.href = "../manageproject.php?pid=" + rowData['ProjectID'];
},
pager: "#spager",
loadonce: true,
rowNum: 20,
rowList: [],
width: "auto",
height: "auto",
caption: "",
sortname: "",
sortorder: "",
viewrecords: true,
gridview: true
});
var srchres = <?php echo json_encode($projects_array); ?>;
for(var i=0;i<srchres.length;i++)
jQuery("#slist").addRowData(srchres[i].id,srchres[i]);
});
Try with the following settings into the grid:
$(document).ready(function () {
var srchres = <?php echo json_encode($projects_array); ?>;
$("#slist").jqGrid({
data: srchres,
datatype: "local",
....
});
...
});
Note the variable srchres and how is defined into the grid options. addRowData is not needed to be used.

jqx - Grid sorting on address column not working

I have used jqx grid for displaying customers data. But when i go for column sorting on address column it's not working. I think it's happen because address contains numeric value. here is code
var source = {
datatype: "json",
datafields: [
{ name: 'aa', type: 'string'},
{ name: 'bb', type: 'string'},
{ name: 'cc', type: 'string'}
],
url: senddata,
sortcolumn: 'create_date',
sortdirection: 'desc'
};
$("#jqxgrid").jqxGrid(
{columns: [
{ text: 'Address', datafield: 'aa', width: '30%' },
{ text: 'Total Units', datafield: 'bb', width: '10%' },
{ text: 'Extras', datafield: 'cc', width: '14%' }
],
ready: function (){$('#jqxgrid').jqxGrid({ pagesizeoptions: page_opt});}
So i want it for first column (address) which contains numeric value at starting position in some of them. Thanks in advance.
Because of returning address as link(with anchor) from back-end it doesn't work. Because jqx grid considering whole tag for sorting.
After creating custom link and only returning address as text from back-end, it works for me.

POST extjs 4 fields to PHP on store.load

I'm migrating from extjs 2.2 to extjs 4.0. My code filters my grid data trough an php (the proxy url) that POST the some ext fields.
etx store:
var store = Ext.create('Ext.data.Store', {
model: 'Company',
remoteSort: true,
remoteFilter: true,
proxy: {
// load using script tags for cross domain, if the data in on the same domain as
// this page, an HttpProxy would be better
type: 'ajax',
url: "logica_de_aplicacao/usuario/grid_usuarios_dados.php",
reader: {
root: 'results',
totalProperty: 'total'
},
// sends single sort as multi parameter
simpleSortMode: true
},
sorters: [{
property: 'nome',
direction: 'ASC'
}]
});
ext fields (two exemples, there are too many fields):
var txtLogin = new Ext.form.TextField({
fieldLabel: "Login",
width: 200
});
var txtAtivo = new Ext.form.ComboBox({
fieldLabel: 'Ativo',
width: 200,
name: 'ativo',
editable: false,
disableKeyFilter: true,
forceSelection: true,
triggerAction: 'all',
mode: 'local',
store: new Ext.data.SimpleStore({
id: 0,
fields: ['value', 'text'],
data : [['S', 'Sim'], ['N', 'Não']]
}),
valueField: 'value',
displayField: 'text',
hiddenName: 'ativo'
});
Filtering:
tbar: [{
text: "Adicionar Filtro", //add filter
tooltip: "Filtre os resultados",
iconCls:"icone_filtro",
handler: function() {
iniciaPesquisa();
}
}, {
text: "Remover Filtro", //remove filter
tooltip: "Cancelar o filtro",
iconCls:"icone_cancel_filtro",
handler: function() {
store.baseParams = {
login: "",
nome: "",
privilegio: "",
ativo: "",
municipio: ""
};
store.removeAll();
store.load();
}
}],
PHP:
...
$login = $_POST["login"];
...
$ativo = $_POST["ativo"];
In ext 2.2 that would normally post the fields content on the store.load() action, but nothing happens now. How could I post those fields in ext 4?
(apologizes for the bad english)
It's actually simpler now, just use store.clearFilter()
store.clearFilter();
store.removeAll();
store.load();
var store = Ext.create('Ext.data.Store', {
model: 'Company',
remoteSort: true,
remoteFilter: true,
proxy: {
// load using script tags for cross domain, if the data in on the same domain as
// this page, an HttpProxy would be better
type: 'ajax',
url: "logica_de_aplicacao/usuario/grid_usuarios_dados.php",
baseParams: { //here you can define params you want to be sent on each request from this store
login: "",
nome: "",
privilegio: "",
ativo: "",
municipio: ""
},
reader: {
root: 'results',
totalProperty: 'total'
},
// sends single sort as multi parameter
simpleSortMode: true
},
sorters: [{
property: 'nome',
direction: 'ASC'
}]
});
tbar: [{
text: "Adicionar Filtro", //add filter
tooltip: "Filtre os resultados",
iconCls:"icone_filtro",
handler: function() {
iniciaPesquisa();
}
}, {
text: "Remover Filtro", //remove filter
tooltip: "Cancelar o filtro",
iconCls:"icone_cancel_filtro",
id : 'BtnRemoveFilter', // added this
handler: function() {
store.baseParams = {
login: "",
nome: "",
privilegio: "",
ativo: "",
municipio: ""
};
store.removeAll();
store.load();
}
}],
var Btn = Ext.getCmp('BtnRemoveFilter');
Btn.on('click', function(){
store.load({
params: { //here you can define params on 'per request' basis
login: "the value u want to pass",
nome: "the value u want to pass",
privilegio: "the value u want to pass",
ativo: "the value u want to pass",
municipio: "the value u want to pass"
}
})
});
try this code is working or not.i think this is what u want

Extjs grid doesnot display the table data

I have used EXTJS for grid display and for pagination also.My problem is that grid panel is getting displayed but the table contents are not displayed in the grid.I have used php and mysql.
Php code to retrieve data from table :
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL | E_STRICT);
define('_PJEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);
define('PJPATH', dirname(__FILE__));
define('DB_DIR', PJPATH . DS . 'DB_SETUP');
define('LIB_DIR', PJPATH . DS . 'library');
if (file_exists(PJPATH . DS . 'template.php')) {
include_once PJPATH . DS . 'template.php';
include_once PJPATH . DS . 'process.php';
include_once LIB_DIR . DS . 'factory.php';
}
$page_num = $_REQUEST['start'];
$limit=$_REQUEST['limit'];
$data = PJFactory::getJobAuditDetails();
$rows= mysql_num_rows($data);
$result = PJFactory::displayJobAuditDetail($page_num, $limit);
while($num_rows= mysql_fetch_array($result,MYSQLI_ASSOC)){
$display[]=array('id'=>$num_rows['id'],
'id_job_audit'=>$num_rows['id_job_audit'],
'error_message'=>$num_rows['error_message']
);
}
$myData = array('errorDisplay'=>$display, 'totalCount'=>$rows);
echo json_encode($myData);
?>
Java Script page
Ext.require([
'Ext.grid.*',
'Ext.data.*'
]);
Ext.onReady(function(){
// Ext.QuickTips.init();
var store =new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'processdisplay.php'
// method: 'GET'
}) ,
//type: 'ajax',
reader: new Ext.data.JsonReader({
type: 'json',
root:'errorDisplay',
totalProperty:'totalCount',
id: 'id'
},
[
{name: 'id',mapping: 'id',type: 'int'},
{name:'id_job_audit',mapping:'id_job_audit',type:'string'},
{name :'error_message',mapping:'error_message',type:'string'}
]
),
autoLoad : true,
idProperty: 'id'
});
// baseParams:{task: "LISTING"}
var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{header: 'id', width: 30, sortable: true, dataIndex: 'id'},
// {header: 'id', width: 100, sortable: true, dataIndex: 'id'},
{header: 'id_job_audit', width: 100, sortable: true, dataIndex: 'id_job_audit'},
{header: 'error_message', width: 250, sortable: true, dataIndex: 'error_message'}
],
stripeRows: true,
height:250,
width:500,
title:'Job Error Details',
bbar: new Ext.PagingToolbar({
pageSize:20,
store: store,
displayInfo: true,
displayMsg: 'Displaying topics {0} - {1} of {2}',
emptyMsg: "No topics to display"
})
});
//store.show();
store.load();
// render this grid to paging-grid element
grid.render('paging-grid');
});
I have checked the result for echo json_encode($myData) in firebug.It displayed correctly and checked JSON option also in firebug it shows like below
errorDisplay
[Object { id="1", id_job_audit="4", error_message="Missing Category for Pa...avigation Id - 10097374"}, Object { id="2", id_job_audit="4", error_message="Missing Category for Pa...avigation Id - 10097374"}, Object { id="3", id_job_audit="4", error_message="Missing Category for Pa...avigation Id - 10097374"}, 22 more...]
totalCount
102
I dont know where am wrong.The grid is empty,displays message as "no topics to disply".
please make to clear.
Edit:
I have tested by encoding only the result which i retrieved from db.At the time I got display in the grid of first 25 records. i.e(echo json_encode($display) in my case)
Is array result only capable of encode in JSon?. Because Before I got in firebug as object of arrays.
The reader is a property of the proxy, not the store. Also, you should use a model to provide the fields. Should look something like this (untested):
Ext.require(['Ext.grid.*', 'Ext.data.*']);
Ext.define('MyModel', {
extend: 'Ext.data.Model',
fields: [{
name: 'id',
mapping: 'id',
type: 'int'
}, {
name: 'id_job_audit',
mapping: 'id_job_audit',
type: 'string'
}, {
name: 'error_message',
mapping: 'error_message',
type: 'string'
}]
});
Ext.onReady(function() {
var store = new Ext.data.Store({
model: MyModel,
autoLoad: true,
proxy: {
type: 'ajax',
url: 'processdisplay.php',
reader: {
type: 'json',
root: 'errorDisplay',
totalProperty: 'totalCount'
}
})
});
// baseParams:{task: "LISTING"}
var grid = new Ext.grid.GridPanel({
store: store,
columns: [{
header: 'id',
width: 30,
sortable: true,
dataIndex: 'id'
},
// {header: 'id', width: 100, sortable: true, dataIndex: 'id'},
{
header: 'id_job_audit',
width: 100,
sortable: true,
dataIndex: 'id_job_audit'
}, {
header: 'error_message',
width: 250,
sortable: true,
dataIndex: 'error_message'
}],
stripeRows: true,
height: 250,
width: 500,
title: 'Job Error Details',
bbar: new Ext.PagingToolbar({
pageSize: 20,
store: store,
displayInfo: true,
displayMsg: 'Displaying topics {0} - {1} of {2}',
emptyMsg: "No topics to display"
})
});
//store.show();
store.load();
// render this grid to paging-grid element
grid.render('paging-grid');
});

ExtJs 4 FilterFn: function unexpected behavior

I have a xtype:'combo' which looks like this:
xtype: 'combo',
id: 'records_list_author_id',
emptyText: 'Filter By author',
editable: false,
store: 'FilterRecordsByAuthor',
displayField: 'firstname',
valueField: 'id',
lastQuery: '',
triggerAction: 'all',
queryMode: 'local',//'remote',
typeAhead: false,
width: 200
I use very simple story with proxy defined as this:
proxy: {
type: 'ajax',
actionMethods: 'POST',
api: {
read: g_settings.baseUrl + 'index.php/record/getAuthorsOfRecords'
},
reader: {
type: 'json',
root: 'data',
idProperty: 'id',
successProperty: 'success'
//totalProperty: 'totalCount'
}
}
and in my controller I have this:
var comboBoxFilterByAuthorSt = this.getFilterRecordsByAuthorStore();
comboBoxFilterByAuthorSt.clearFilter(true);
comboBoxFilterByAuthorSt.filter ({
filterFn: function(item) {
return item.get('category_id') == sel.raw.categoryId;
}
})
So for example when I have sel.raw.categoryId = 1 it matches records with 2 different authors in my store, but in the combobox I get only one of the names. In other cases I also get uncorrect result. I checked my sql query and it works OK and returns the correct info, but when I filter the store I don't get matches I know they exist. Maybe the problem is somewhere else, but maybe I miss something when making the filters. So - any advice is appreciated.
Thanks
Leron

Categories