Can Some one help me, I have a jqgrid and I want to highlight the row if the checkbox is true, thanks!!
this is what i want to make in this project...
function loadjqGrid(jsonGridData){
var xaxis=1300
var yaxis = $(document).height();
yaxis = yaxis-500;
getGrids();
$("#maingrid").jqGrid({
url:'models/mod.quoservicetypedetails.php?ACTION=view',
mtype: 'POST',
datatype: 'xml',
colNames:getColumnNames(jsonGridData),
colModel :[
{name:'TypeID', index:'TypeID', width:350,hidden:true, align:'center',sortable:false,editable:true,
edittype:"select",editoptions:{value:getTypeID()},editrules: { edithidden: true}},
{name:'Order1', index:'Order1', width:80, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},
{name:'Order2', index:'Order2', width:80, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},
{name:'Order3', index:'Order3', width:80, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},
{name:'Description', index:'Description', width:140, align:'center',sortable:false,editable:true,
edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},
{name:'Notes', index:'Notes', width:120, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},
{name:'Measure', index:'Measure', width:80, align:'center',sortable:false,editable:true, edittype:"textarea", editoptions:{size:"30",maxlength:"30"}},
{name:'UnitPrice', index:'UnitPrice', width:100, align:'center',sortable:false,editable:false,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},
{name:'Remarks', index:'Remarks', width:140, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},
{name:'UnitCost', index:'UnitCost', width:100, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},
{name:'Service', index:'Service', width:120, align:'center',sortable:false,editable:true,edittype:"textarea",editoptions:{size:"30",maxlength:"30"}},
//If the GroupHeader is true the row background is yellow
{name:'GroupHeader', index:'GroupHeader', width:100, align:'center',sortable:false,editable:true,formatter:'checkbox', edittype:'checkbox', type:'select', editoptions:{value:"1:0"}},
{name:'IsGroup', index:'IsGroup', width:80, align:'center',sortable:false,editable:true,formatter:'checkbox', edittype:'checkbox', type:'select', editoptions:{value:"1:0"}},
],
viewrecords: true,
rowNum:20,
sortname: 'id',
viewrecords: true,
sortorder: "desc",
height: yaxis,
pager : '#gridpager',
recordtext: "View {0} - {1} of {2}",
emptyrecords: "No records to view",
loadtext: "Loading...",
pgtext : "Page {0} of {1}",
height: yaxis,
width: xaxis,
shrinkToFit: false,
multiselect: true,
editurl:'models/mod.quoservicetypedetails.php?ACTION=edit'
});
}
How could I do this? Can someone help me?
I described in the answer one good way how you can implement the highlighting.
Version 4.3.2 of jqGrid has new feature - rowattr callback (see my original suggestion), which was introduced especially for cases like yours. It allows you to highlight some rows of grid during filling of the grid. To have the best performance advantage you should use gridview: true additionally. By the way I recommend you to use gridview: true in all jqGrids.
The usage of rowattr callback is very easy:
gridview: true,
rowattr: function (rd) {
if (rd.GroupHeader === "1") { // verify that the testing is correct in your case
return {"class": "myAltRowClass"};
}
}
The CSS class myAltRowClass should define background color of highlighted rows.
The corresponding demo you can find here:
Because in your demo you need just highlight and not select the rows I didn't used multiselect: true in my demo. In case of multiselect: true it works exactly in the same way.
At the end of my answer I would like to recommend you to use column templates. The feature will make your code shorter, more readable and easy to maintain. What you need to do is the following:
you can include common or the most frequently used settings from column definitions in cmTemplete. In your case it could be
cmTemplate: {align: 'center', sortable: false, editable: true, width: 80}
then you can define some variables which describe common properties which you use frequently in some columns. For example:
var myCheckboxTemplate = {formatter: 'checkbox', edittype: 'checkbox', type: 'select',
editoptions: {value: "1:0"}},
myTextareaTemplate = {edittype: "textarea",
editoptions: {size: "30", maxlength: "30"}};
after that you can use myCheckboxTemplate and myTextareaTemplate inside of colModel which will reduced in your case to the following
colModel: [
{name: 'TypeID', index: 'TypeID', width: 350, hidden: true, edittype: "select",
editoptions: {value: getTypeID()}, editrules: { edithidden: true}},
{name: 'Order1', index: 'Order1', template: myTextareaTemplate},
{name: 'Order2', index: 'Order2', template: myTextareaTemplate},
{name: 'Order3', index: 'Order3', template: myTextareaTemplate},
{name: 'Description', index: 'Description', width: 140, template: myTextareaTemplate},
{name: 'Notes', index: 'Notes', width: 120, template: myTextareaTemplate},
{name: 'Measure', index: 'Measure', template: myTextareaTemplate},
{name: 'UnitPrice', index: 'UnitPrice', width: 100, editable: false, template: myTextareaTemplate},
{name: 'Remarks', index: 'Remarks', width: 140, template: myTextareaTemplate},
{name: 'UnitCost', index: 'UnitCost', width: 100, template: myTextareaTemplate},
{name: 'Service', index: 'Service', width: 120, template: myTextareaTemplate},
//If the GroupHeader is true the row background is yellow
{name: 'GroupHeader', index: 'GroupHeader', width: 100, template: myCheckboxTemplate},
{name: 'IsGroup', index: 'IsGroup', template: myCheckboxTemplate}
],
cmTemplate: {align: 'center', sortable: false, editable: true, width: 80},
Related
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.
Good day,
I'm pretty new in extjs 5 and mvvm. I want to make an ajax request in order to display a treepanel with datas caught with a php.
Here is my store
Ext.define('MyApp.store.servicesStore', {
extend: 'Ext.data.TreeStore',
// alias: 'store.servicesStore',
storeId : 'servicesStore',
model : 'MyApp.model.servicesModel',
proxy: {
type: 'ajax',
url: 'app/store/data/GetServices.php'
},
root: {
text: 'Events',
id: 'root'
},
autoLoad: true,
folderSort: true
});
I've seen that a "success" can resolve that issue but I don't need a succes as it's only displayed in a treePanel
Ext.define('MyApp.view.tabServices.servicesTab', {
extend: 'Ext.tree.Panel',
xtype: 'servicesTab',
layout: {
type: 'border'
},
useArrows: true,
rootVisible: false,
store: {type: 'servicesStore'},
forceFit: true,
columns: [{
xtype: 'treecolumn',
dataIndex: 'text',
width: 600
}, {
dataIndex: 'mbt',
cls: 'mbtcss',
width: 80
}, {
dataIndex: 'bt',
cls: 'btcss',
width: 75
}, {
dataIndex: 'details', // port separated from rest
width: 60
}, {
dataIndex: 'code',
width: 80
}]
});
So, when I launch my app, the "You're trying to decode an invalid JSON String" appears, how can I do to make it understand that I actually use a php file?
More precisely, that code is working in extjs 3.4
To run the PHP code which did work under ExtJS 4 you must either modify your PHP to return the data in JSON format. Or otherwise you set your "enable compatibility" to version 4.
See "Enabling Compatibility" under http://docs.sencha.com/extjs/5.0/whats_new/5.0/extjs_upgrade_guide.html#Enabling_Compatibility.
compatibility: {
ext: '4.2'
}
I'm using jqgrid to show data from a database, I have this HTML file:
<script type="text/javascript">
jQuery().ready(function (){jQuery("#tblclientes").jqGrid({
url: "category.php",
datatype: "xml",
mtype: "GET",
colNames: ["ID", "Categorias Es", "Categorias En", "Categorias Ru"],
colModel: [
{ name: "idCategoria", width: 55 },
{ name: "nomCategoriaEs", width: 200 },
{ name: "nomCategoriaEn", width: 200, align: "right" },
{ name: "nomCategoriaRu", width: 200, align: "right" },
],
pager: jQuery("#paginacion"),
rowNum:10,
rowList:[10,20,30],
sortname: "idCategoria",
sortorder: "desc",
viewrecords: true,
gridview: true,
autoencode: true,
caption:"XML Example" }).navGrid('#paginacion',{edit:false,add:false,del:false});
});
</script>
And this is my XML file created by the PHP file:
<?xml version='1.0' encoding='utf-8'?><rows><page>1</page><total>2</total><records>13</records><row id="1"><cell>1</cell><cell>Coke Drums</cell><cell>Coke Drums</cell><cell>Коксовые камеры</cell></row><row id="2"><cell>2</cell><cell>Columnas</cell><cell>Columns</cell><cell>Колонны</cell></row><row id="3"><cell>3</cell><cell>Reactores</cell><cell>Reactors</cell><cell>Реакторы</cell></row><row id="4"><cell>4</cell><cell>Intercambiadores de Calor</cell><cell>Heat Exchangers</cell><cell>Теплообменное оборудование</cell></row><row id="5"><cell>5</cell><cell>Autoclaves</cell><cell>Autoclaves</cell><cell>Автоклавы</cell></row><row id="6"><cell>6</cell><cell>Separadores</cell><cell>Separators</cell><cell>Сепараторы</cell></row><row id="7"><cell>7</cell><cell>Drums</cell><cell>Drums</cell><cell>Баки для нефтепродуктов</cell></row><row id="8"><cell>8</cell><cell>Módulos / Skid</cell><cell>Process Modules / Skid</cell><cell>Технологические модули, модульные основания</cell></row><row id="9"><cell>9</cell><cell>Tanques</cell><cell>Storage Tanks</cell><cell>Резервуары для хранения нефтепродуктов</cell></row><row id="10"><cell>10</cell><cell>Fundaciones OWF</cell><cell>OWF Fundations</cell><cell>Фундаменты для ветровых энергоустановок</cell></row></rows>
The Jqgrid appears as I want, but without data.
I don't see any important errors in the code or in the data which you posted. The demo uses the same code (with minimal modifications) and the same data saved as file and all works. I would recommend you to use loadError callback (see the answer) to see more information which kind of error you have.
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');
});
I currently have a JQGrid implementation. The first time I run the search it populates the grid just fine. When I click the search again, even if I use the same criteria the grid refreshes blank instead of using the returned data. Does anyone have any thoughts as to why this would be?
Here is my searchfunction:
function searchlibrary(searchInfo){
if(searchInfo == undefined){
searchInfo = null;
}
$("#searchlist").jqGrid({
url:'./searchlibrary',
datatype: 'json',
mtype: 'POST',
postData: searchInfo,
colNames:['Resource Name','Unit', 'Topic','Document Type','Content Type','Select'],
colModel :[
{name:'resourceName', index:'resourceName', width:374, align:'left'},
{name:'unit', index:'unitID', width:40, align:'center',sortable:true,sorttype:'text'},
{name:'topic', index:'topicID', width:220, align:'center',sortable:true},
{name:'docType', index:'docTypeID', width:97, align:'center',sortable:true},
{name:'contentType', index:'contentTypeID', width:97, align:'center',sortable:true},
{name: 'resourceID', width:55, align: "center", sortable: false, editable: true, edittype: "checkbox", editoptions: {value: "Yes:No"}}
],
rowNum:20,
sortname: 'resourceName',
sortorder: 'asc',
viewrecords: true,
gridview: true,
width:878,
height:251
});
$("#searchlist").jqGrid('setLabel','resourceName','',{'text-align':'left','padding-left':'5px'});
}
There is a dropwdown of items above the grid. When one item is selected either another dropdown with more content shows, or a textbox shows. Then when the user clicks the submit button the contents of the dropdowns/textfield are taken by jquery and an object is built. That object is passed as the searchInfo argument when the searchlibrary function is called. That is then used as the postData in the jqgrid call. I've logged to make sure the object that's being passed is always correct. For some reason anything after the first call to this function returns a blank jqgrid. Also, just for further understand the url called to retrieve the info is a php file that generates json data.
UPDATE
Here's my attempt at Oleg's suggestion. I must be missing something. I'm getting blanks again. Here's the code I'm using now.
$(document).ready(function(){
$("#searchlist").jqGrid({
url:'./searchlibrary',
datatype: 'json',
mtype: 'POST',
postData: {data: function(){var myvar = new Object(); myvar = getSearchData(); console.log(myvar); return myvar;}},
colNames:['Resource Name','Unit', 'Topic','Document Type','Content Type','Select'],
colModel :[
{name:'resourceName', index:'resourceName', width:380, align:'left'},
{name:'unit', index:'unitID', width:40, align:'center',sortable:true,sorttype:'text'},
{name:'topic', index:'topicID', width:220, align:'center',sortable:true},
{name:'docType', index:'docTypeID', width:97, align:'center',sortable:true},
{name:'contentType', index:'contentTypeID', width:97, align:'center',sortable:true},
{name: 'select', width:55, align: "center", sortable: false, editable: true, edittype: "checkbox", formatter:"checkbox", editoptions: {value: "Yes:No"},formatoptions: {disabled : false}}
],
rowNum:20,
sortname: 'resourceName',
sortorder: 'asc',
viewrecords: true,
gridview: true,
width:878,
height:251
});
$("#searchlist").jqGrid('setLabel','resourceName','',{'text-align':'left'});
function getSearchData(){
var searchType = $('select[name="searchtype"]').val();
var searchCriteria = "";
var searchInfo = new Object();
if(searchType=="Unit" || searchType=="Topic" || searchType=="Document Type"){
searchCriteria = $('select[name="searchcontent_select"]').val();
} else if(searchType=="Resource Name" || searchType=="Keyword"){
searchCriteria = $('input[name="searchcontent_text"]').val();
}
searchInfo = {type:searchType, criteria:searchCriteria}
return searchInfo;
}
$('#searchbutton').click(function(ev){
$("#searchlist").trigger('reloadGrid');
});
});
WORKING SOLUTION
$(document).ready(function(){
$("#searchlist").jqGrid({
url:'./searchlibrary',
datatype: 'json',
mtype: 'POST',
postData: {type: function(){return $('select[name="searchtype"]').val();},
criteria: function(){return getSearchData();}
},
colNames:['Resource Name','Unit', 'Topic','Document Type','Content Type','Select'],
colModel :[
{name:'resourceName', index:'resourceName', width:380, align:'left'},
{name:'unit', index:'unitID', width:40, align:'center',sortable:true,sorttype:'text'},
{name:'topic', index:'topicID', width:220, align:'center',sortable:true},
{name:'docType', index:'docTypeID', width:97, align:'center',sortable:true},
{name:'contentType', index:'contentTypeID', width:97, align:'center',sortable:true},
{name: 'select', width:55, align: "center", sortable: false, editable: true, edittype: "checkbox", formatter:"checkbox", editoptions: {value: "Yes:No"},formatoptions: {disabled : false}}
],
rowNum:20,
sortname: 'resourceName',
sortorder: 'asc',
viewrecords: true,
gridview: true,
width:878,
height:251
});
$("#searchlist").jqGrid('setLabel','resourceName','',{'text-align':'left'});
function getSearchData(){
var searchType = $('select[name="searchtype"]').val();
var searchCriteria = "";
var searchInfo;
if(searchType=="Unit" || searchType=="Topic" || searchType=="Document Type"){
searchCriteria = $('select[name="searchcontent_select"]').val();
} else if(searchType=="Resource Name" || searchType=="Keyword"){
searchCriteria = $('input[name="searchcontent_text"]').val();
}
searchInfo = {type:searchType, criteria:searchCriteria}
return searchCriteria;
}
$('#searchbutton').click(function(ev){
$("#searchlist").trigger('reloadGrid');
});
});
It turns out the solution was to unload the grid first. So I added this line:
$("#searchlist").jqGrid('GridUnload');
I put in the the searchlibrary function right above the
$("#searchlist").jqGrid({
That causes the grid to completely unload the get reloaded with the proper content.
As a note I found the idea for the solution here.
The usage of $("#searchlist").trigger("reloadGrid") is more effective as the usage of $("#searchlist").jqGrid('GridUnload'). It's understand that $("#searchlist").jqGrid({...]); creates column headers, and many other grid elements. So you should create the grid once with respect of $("#searchlist").jqGrid({...]); and later use only $("#searchlist").trigger("reloadGrid").
I would recommend you to use postData with functions as properties (see here). For example
postData: {
type: function () {
return $('select[name="searchtype"]').val(); // get some data
},
criteria: function () {
return getSearchData();}
}
}
Every time if the user click on '#searchbutton' button or do sorting or paging of data the type and criteria methods will be called. So you can return current values for the proerties and send the data to the server which the user fill in some controls on the page.