I have a grid populated by a database. One of the columns is a concat of 2 columns in another table. In this case it is a team's location and name. However, when I click on edit and the edit form gets populated, it always picks the first team in the dropdown as opposed to the actual team in the database.
Here is some of the relevant code:
jQuery("#listPlayer").jqGrid({
url:'../controller/playerGrid.php',
datatype: "json",
colNames:['ID','First Name','Last Name', 'Team'],
colModel:[
{name:'id', index:'id', width:20, editable:false, hidden:true},
{name:'first_name', index:'first_name', width:80, editable:true, editrules: {required: true}},
{name:'last_name', index:'last_name', width:80, editable:true, editrules: {required: true}},
{name:'idTeam', index:'idTeam', width:50, editable:true, editrules: {required: true}, edittype: 'select', editoptions: { dataUrl: "../controller/listTable.php?query=team" } }
],
rowNum:50,
rowTotal: 2000,
rowList : [20,30,50],
mtype: "POST",
rownumbers: true,
rownumWidth: 40,
gridview: true,
pager: '#pagerPlayer',
sortname: 'last_name',
viewrecords: true,
sortorder: "asc",
caption: "Player Manager",
editurl: "../controller/playerEditGrid.php"
And this is what the SQL query in listTable.php looks like:
SELECT t.id, CONCAT(t.location, ' ', t.name,' (', l.abbr, ')' ) as idTeam FROM team t, league l WHERE t.idLeague = l.id ORDER BY t.location
I know the problem lies in the fact that it's a concatenation as opposed to a single column but I'm sure there's a way around it... I just don't know it.
I haven't used it this way but the following part of jqgrid help should be applicable for your case: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:common_rules#select
The return from your dataurl should already be a valid HTML select element like:
<select>
<option value='1'>One</option>
<option value='2'>Two</option>
...
</select>
refer 3. Setting the editoptions dataUrl parameter in the above url.
hope this helps!
Related
I'm trying to convert an existing "select" dropdown filter on a table generated via the DataTables library to be able to handle multiple options, and though I think I have it correct on the front-end Javascript, I'm having trouble figuring out how to handle it in the back-end PHP.
The below is from the script in the front-end view, which makes the Ajax Post request:
<script>
function generateTable() {
var oTable = $('#MyData').dataTable({
"aaSorting": [
[1, "desc"]
],
"aLengthMenu": [
[10, 25, 50, 100, 200],
[10, 25, 50, 100, 200]
],
"iDisplayLength": <?= $Settings->rows_per_page ?>,
'bProcessing': true,
'bServerSide': true,
'sAjaxSource': '/my/getData/path',
'fnServerData': function(sSource, aoData, fnCallback) {
// ...SNIP...
aoData.push({
"name": "some_status",
"value": $("#some_status").val()
});
$.ajax({
'dataType': 'json',
'type': 'POST',
'url': sSource,
'data': aoData,
'success': fnCallback
});
},
"aoColumns": [],
}).fnSetFilteringDelay().dtFilter([
// ...SNIP...
{
column_number: 4,
filter_default_label: "[<?= lang('some_status'); ?>]",
filter_type: "multi_select",
data: []
},
// ...SNIP...
], "footer");
}
</script>
I can confirm that the selected values are added to an array by console logging the $("#some_status").val(). So my assumption was that it would be passed to the backend as an array as well, but apparently not.
What actually happens is the first selection goes fine, but any subsequent selection clears the table, and only works if there's a single value selected, leaving me to believe that only the first selection is pushed to the aoData array.
In PHP I have:
$this->load->library('datatables');
$this->datatables
->select("id, date, reference_no, supplier, some_status")
->from('purchases');
$some_status = $this->input->post('some_status');
if ($some_status != '') {
$this->datatables->where('status', $some_status);
}
How do I handle the some_status value if it's an array, or how do I make sure it even is an array after it was pushed toaoData?
Any help will be appreciated!
EDIT:
To clarify, by console logging the result like below returns the correct selection as I add and remove selections from the multi-select dropdown:
console.log($("#some_status").val());
If I select "Top option" from the dropdown, I get:
[
"top_option"
]
When I then select "Another option" as well, I get:
[
"top_option", "another_option"
]
So the JS side is handling the multi-select, but I don't know if the below is correct, as it works only with a single select, nothing more:
$some_status = $this->input->post('some_status');
if ($some_status != '') {
$this->datatables->where('status', $some_status);
}
I dont know how to tell but i still dont get it right. This is my code :
Ext.define("PL.view.list.listOnly", {
extend: 'Ext.form.Panel',
alias: 'widget.listlistonly',
config:{
fullscreen: true,
title: 'Master barang',
items:[{
xtype : 'panel',
layout: {
type: 'fit',
align : 'stretch',
pack : 'start',
},
defaults: {
allowBlank: true,
msgTarget: 'side',
labelWidth: 60,
margin: '5 5 5 5',
},
items:[{
xtype:'list',
height: '100%',
masked: { xtype: 'loadmask',message: 'Loading...' },
scrollable: {
direction: 'vertical',
directionLock: true
},
store:{
fields: [{
name:'szName',
},{
name:'szProductID',
},{
name:'szBarcode',
}],
autoLoad: true,
pageSize: 20,
proxy: {
type: 'ajax',
url: 'store/product/loadData.php',
pageParam: 'param',
reader: {
type: 'json',
rootProperty: 'topics',
}
}
},
variableHeights: false,
useComponents: true,
itemTpl: '<div class="myButton">' +
'<input type="button" name="{szProductID}" value="Edit" ' +
'style="padding:3px;">' +
'</div>' +
'<div class="myContent">'+
'<div>PLU : <b>{szProductID}</b>, Barcode: <b>{szBarcode}</b></b></div>' +
'<div>Nama: <b>{szName}</b></div>' +
'</div>',
}]
}],
scrollable : false,
},
});
And this is what i get from json :
{"topics": [{
"szProductID": 1001,
"szBarcode": 002,
"szName": "STANDARD BLACK"
},{
"szProductID": 1100420020479,
"szBarcode": 1100420020479,
"szName": "STANDARD BLUE"
}],
"totalCount": 2}
As you can see, there is a '002' (szBarcode field), and this is my problem. The list only show '2' instead of '002'. This should show '002' as szBarcode but i dont know how to fix this.
Any help would appreciate
The problem is that barcode: 002 and barcode: 2 mean exactly the same in JSON format. Prepended zeros for numbers just don't count.
There are about four different things you can possibly do.
If you can access the server code, you can change it to send you the barcode field as a string (barcode:"002").
If your barcode ALWAYS has a certain length (say 13), you can work with the number you have, and pad it to the required length again. Please be aware that after a certain length, there are precision issues because numbers are stored in fixed-length memory, while a string's memory always is as long as needed. Sample conversion code:
name:'barcode',
convert:function(value) {
var str = value.toString(),
pad = "0000000000000"; // expand to length of your number
return pad.substring(0, pad.length - str.length) + str);
}
(Bonus: This code does not break when someone does (1) afterwards...)
If you have no other barcode fields in your JSON, you could use a regular expression to add the necessary quotes to the JSON client-side before deserialization.
You could override ExtJS's default JSON serialization/deserialization code. Please note that this is not as easy as it sounds and may have quite some side effects. This is the only suitable way if you want to send barcode as zero-padded JSON numbers back to the server as well.
I'm trying to pass column values to php load the select item on the edit form based on the column values.
dataUrl:'includes/Opera_classif.php?Op=local&id=' +ID +Description +id_local
JS
mtype: 'GET',
colNames: [ "ID","Descrição","ID Local", "Local","Select Local"],
colModel: [
{name:'ID',index:'ID', width:20, sorttype:"int"},
{name:'Description',index:'Description', width:150, editable: true,editrules:{required:true}},
{name:'id_local',index:'id_local',hidden:true, width:20, editable: true,editrules:{required:true}},
{name:'Local_Description',index:'Local_Description', width:100, editable: true,editrules:{required:true}},
{
name:'escolhe_local',index:'escolhe_local', width:80,resizable:true, hidden:true, editrules:{edithidden: true },
align:"left",sorttype:"text",editable:true,edittype:"select",
editoptions:{dataUrl:'includes/Opera_classif.php?Op=local'}
}
One can use dataUrl defined as function (see here and here). The function dataUrl get 3 parameter (the first is the rowid, the second is the value from the current column - Local_Description in your case) and this will be initialized to DOM of the grid (so you can use $(this).jqGrid("getRowData", rowid) or $(this).jqGrid("getCell", rowid, "Description") for example). In the way you can generate any dataUrl value which you need.
I have list of links in one page which is dynamically created. I want to do when I click on one link another page will be open and according to link id which is i am sending the data will be fetch from database and load into a pagination ext data grid.
Bellow in my Javascript code
var extGrid = null;
var center_data_store=null;
var exam_id = null;
Ext.onReady(function(){
// create the data store
exam_id = document.getElementById("hdnExamId").value;
//I am getting id from one hidden field.
//alert(exam_id);// Id is coming.
multiple_choice_all_data_store = new Ext.data.JsonStore({
totalProperty: 'total', // total data, see json output
root: 'results', // see json output
url: 'multiple_choice_all_data_grid.php"?exm_id="+exam_id',
//in above url I am passing data.
fields: [
{name: 'OEXM_Id', type: 'int'},
'OEXM_txtareaQuestion','OEXM_rbtnOption','OEXM_txtOption1','OEXM_txtOption2','OEXM_txtOption3','OEXM_txtOption4','OEXM_txtExamId','OEXM_txtExamName'
]
});
// load data from the url ( data.php )
multiple_choice_all_data_store.load({params:{start: 0, limit: 15}});
// create the Grid
var multiplechoicealldataGrid = new Ext.grid.GridPanel({
store: multiple_choice_all_data_store,
columns: [
new Ext.grid.RowNumberer(),
//{header: 'ID', width: 30, sortable: true, dataIndex: 'OEXM_Id',hidden:false},
{header: 'Question', width: 300, sortable: true, dataIndex: 'OEXM_txtareaQuestion',hidden:false},
{header: 'Answer', width: 100, sortable: true, dataIndex: 'OEXM_rbtnOption',hidden:false},
{header: 'Option1', width: 100, sortable: true, dataIndex: 'OEXM_txtOption1',hidden:false},
{header: 'Option2', width: 100, sortable: true, dataIndex: 'OEXM_txtOption2',hidden:false},
{header: 'Option3', width: 100, sortable: true, dataIndex: 'OEXM_txtOption3',hidden:false},
{header: 'Option4', width: 100, sortable: true, dataIndex: 'OEXM_txtOption4',hidden:false}
],
stripeRows: true,
height:470,
width:792,
title:'All Multiple Choice Question Information',
bbar: new Ext.PagingToolbar({
pageSize: 15,
store: multiple_choice_all_data_store,
displayInfo: true,
displayMsg: 'Displaying Records {0} - {1} of {2}',
emptyMsg: "No topics to display"
})
});
My problem is I am not able to get ID value in my PHP Page.
Try change url in the store definition to 'multiple_choice_all_data_grid.php?exm_id='+exam_id
Then your id should be available in PHP in $_GET['exm_id'] variable
To get a element in ExtJS:
exam_id = Ext.getCmp("hdnExamId").getValue();
The getValue() method is used to retrieve the value of the element.
Edit:
Also fix the url #Lolo is pointing out.
I'm working with jqGrid to develop a time management module for a customer. We have already deployed jqGrid extensively over the rest of the site so we're working to make it fit this role too.
We need to be able to display a column for each day of a calendar month, each day then being split into two columns for overtime worked (HV - text input box) and the reason (R - select dropdown). I've got the grid designed to an extent (overtime/reason columns, list of branch staff etc) but am having trouble writing the processor. The code below shows what I currently have. This populates the grid (via another file) with a list of employees. The column list (day numbers 1-31) is generated from a PHP function which determines the current month and year. Grid.php then posts to gridsave.php when the row is clicked-off.
I would like to be able to determine which field has been edited as easily as possible. I do not want 62 columns (HV and R for each day of a 31 day month) in my database just in case, I'd like to programmatically determine the field id (date) and store that in a date column using my processor. If at all possible, I'd like to only pass modified fields to my processor to save on processing time.
Then, in reverse, I need to be able to extract this information (based on the date determined above) and input it into the correct column in jqGrid.
Needless to say I've now come up against a brick wall and not sure how to proceed on any of the above so will have to bow to superior knowledge. Any assistance in this will be much appreciated!
grid.php
var lastsel2;
jQuery(document).ready(function(){
jQuery("#timeLog").jqGrid({
url:'datagrid.php?module=timemanagement&branchid=<?php echo($branchid); ?>',
editurl: "gridsave.php?branchid=<?php echo($branchid); ?>",
datatype: 'json',
mtype: 'GET',
colNames:['First Name','Surname','Job Title',
<?php
$x = 1;
while($x <= $numdays) {
echo("'HV',");
echo("'R',");
$x++;
}
?>
],
colModel :[
{name:'firstname', index:'firstname', align: 'center', width: 100, searchoptions: { sopt: ['eq', 'ne', 'lt', 'gt', 'cn', 'nc']}},
{name:'lastname', index:'lastname', align: 'center', width: 100, searchoptions: { sopt: ['eq', 'ne', 'lt', 'gt', 'cn', 'nc']}},
{name:'jobtitle', index:'jobtitle', align: 'center', width: 100, searchoptions: { sopt: ['eq', 'ne', 'lt', 'gt', 'cn', 'nc']}},
<?php
$x = 1;
while($x <= $numdays) {
echo("{name:'hv-$x-$month-$year', index:'hv', align: 'center', width: 25, sortable: false, editable: true},");
echo("{name:'r-$x-$month-$year', index:'r', align: 'center', width: 25, sortable: false, editable:true, edittype:'select', editoptions:{value:':;OT:OT;S:S;H:H;OA:OA'}},");
$x++;
}
?>
],
onSelectRow: function(id){
if(id && id!==lastsel2){
$('#timeLog').jqGrid('saveRow',lastsel2);
$('#timeLog').jqGrid('editRow',id,true);
lastsel2=id;
}
},
pager: '#pager',
height: 500,
rowNum:25,
rowList:[25,50,100],
sortname: 'firstname',
sortorder: 'ASC',
viewrecords: true,
}).navGrid('#pager', {search:true, edit: false, add:false, del:false});
});
gridsave.php
// Check for exec permission
define('_CHECKEXEC', TRUE);
// Connect to database
include("./includes/init.inc.php");
if($_GET['oper'] == "edit") {
// Generate query and insert data
$sql = "INSERT INTO tbltimemanagement(userid, hv, r) VALUES ('$_POST[id]', '$_POST[hv]', '$_POST[r]');";
mysql_query($sql);
}