Home › Forums › Guriddo Suito PHP › Get value from select dropdown
$types contains 1:text1;2:text2;3:text3
$grid->setColProperty(“TestType”, array(“label”=>”Type”, “width”=>70, “editable”=>true, “edittype”=>”select”, “formatter”=>”select”, “editoptions”=>array(“value”=>”{$types}”)));
works correctly, however, when iterating through the resultant rows from the grid it is returning the text and I need the value. how do I get this please.
Hello,
It all depends how you get the data when you loop through it.
If you use getRowData or getCell methods the result should be the value of the select and not the text, since these methods automatically calls the needed function to get back the value.
If you use your own method to get the data the of course it will get what is displayed into the grid.
If you prefer to use your way of getting data we recommend you to use the build in jqGrid function $.unformat.select(value, options), where the value is the formated text from the select and the options are the colMoodel options for that field. Example:
1 2 3 4 5 6 7 8 9 10 11 |
var selected_text = 'text1' var model = $("#jqGrid").jqGrid('getGridParam','colModel'); model = model[j]; // j is the index of the field in colModel // Some code befor calling selected_text = '<div>'+selected_text+'</div>'; options = { colModel : model }; var selected_value = $.unformat.select(selected_text, options); |
Hope this helps
Kind Regards,
Will
Guriddo Support Team
I have the search returning the value correctly now but the record that meets the search criteria where LicenceTyepID = 1 is not being displayed. lqGrid.log returns
[1] => Array
(
[time] => 2017-12-19 08:46:57
[query] => SELECT * FROM (SELECT organisation.OrganisationID,
organisation.Name,
organisation.Active,
organisation.PostCode,
replace(organisation.Notes,”’”,”‘”) as Notes,
organisation.DemoAccount,
organisation.LicenceEndDate as LEAfter,
organisation.LicenceEndDate as LEBefore,
licencetype.Name as LicenceType,
organisation.ParentOrganisationID,
organisation.WebServiceID,
” as CandidateEmail,
” as UserName
from organisation
inner join licencetype on organisation.LicenceTypeID = licencetype.LicenceTypeID where 1 = 1 ) gridsearch WHERE (LicenceType = ?) ORDER BY Name asc LIMIT 0, 20
[data] => Array
(
[0] => 1
)
[types] =>
[fields] =>
[primary] =>
[input] =>
)
)
|My code as follows:-
if(!isset($superLogin) ) {
$superLogin = jqGridUtils::GetParam(‘sLogin’,”);
}
$sLogin = $superLogin;
if(!isset($aLicTypes) ) {
$aLicTypes = jqGridUtils::GetParam(‘licType’,”);
}
$licType = $aLicTypes;
if(!isset($aPO) ) {
$aPO = jqGridUtils::GetParam(‘PO’,”);
}
$PO = $aPO;
if(!isset($aWS) ) {
$aWS = jqGridUtils::GetParam(‘WS’,”);
}
$WS = $aWS;
// Create the jqGrid instance
$grid = new jqGridRender($conn);
// enable debugging
$grid->debug = true;
$where = $where.$sOrgs;
// the actual query for the grid data
$grid->SelectCommand = “SELECT organisation.OrganisationID,
organisation.Name,
organisation.Active,
organisation.PostCode,
replace(organisation.Notes,\”’\”,\”‘\”) as Notes,
organisation.DemoAccount,
organisation.LicenceEndDate as LEAfter,
organisation.LicenceEndDate as LEBefore,
licencetype.Name as LicenceType,
organisation.ParentOrganisationID,
organisation.WebServiceID,
” as CandidateEmail,
” as UserName
from organisation
inner join licencetype on organisation.LicenceTypeID = licencetype.LicenceTypeID “.$where;
// set the ouput format to json
$grid->dataType = ‘json’;
// Set the url from where we obtain the data
$grid->setUrl(‘getOrganisations.php?sLogin=’.$superLogin.’&licType=’.$aLicTypes.’&PO=’.$aPO.’&WS=’.$aWS);
// Let the grid create the model
$grid->setColModel(null);
// Set some grid options
$grid->setGridOptions(array(
“caption”=>”Organisations”,
“rowNum”=>20,
“sortname”=>”Name”,
“rowList”=>array(20,100,200),
“height”=>600,
“width”=>960
));
$grid->addCol(array(“name”=>”act”),”last”);
$grid->addCol(array(“name”=>”not”),”last”);
$grid->addCol(array(“name”=>”pog”),”last”);
$grid->addCol(array(“name”=>”lic”),”last”);
$grid->addCol(array(“name”=>”log”),”last”);
$grid->addCol(array(“name”=>”deb”),”last”);
$grid->addCol(array(“name”=>”sup”),”last”);
$grid->addCol(array(“name”=>”sho”),”last”);
$grid->addCol(array(“name”=>”edi”),”last”);
$grid->addCol(array(“name”=>”del”),”last”);
// Change some property of the field(s)
$grid->setColProperty(“OrganisationID”, array(“label”=>”ID”, “width”=>30, “hidden”=>true));
$grid->setColProperty(“Name”, array(“label”=>”Organisation”, “width”=>400, “sorttype”=>”string”, “resizable”=>true, “searchoptions”=>array(“sopt”=>array(“cn”,”nc”,”bw”,”bn”,”eq”,”ne”,”in”,”ni”))));
$grid->setColProperty(“Active”, array(“label”=>”Active”, “width”=>25, “hidden”=>true, “stype”=>”select”,”searchoptions”=>array(“searchhidden”=>true, “sopt”=>array(“eq”), “value”=>” : ;0:inactive;1:active”)));
$grid->setColProperty(“PostCode”, array(“label”=>”Post Code “, “width”=>25, “hidden”=>true, “sortable”=>false, “searchoptions”=>array(“searchhidden”=>true)));
$grid->setColProperty(“Notes”, array(“label”=>” “, “width”=>25, “hidden”=>true, “sortable”=>false));
$grid->setColProperty(“act”, array(“label”=>” “, “width”=>25, “sortable”=>false));
$grid->setColProperty(“not”, array(“label”=>” “, “width”=>25, “sortable”=>false, “search”=>false));
$grid->setColProperty(“pog”, array(“label”=>” “, “width”=>25, “sortable”=>false, “search”=>false));
$grid->setColProperty(“lic”, array(“label”=>” “, “width”=>25, “sortable”=>false, “search”=>false));
$grid->setColProperty(“log”, array(“label”=>” “, “width”=>25, “sortable”=>false, “search”=>false));
$grid->setColProperty(“deb”, array(“label”=>” “, “width”=>25, “sortable”=>false, “search”=>false));
$grid->setColProperty(“sup”, array(“label”=>” “, “width”=>25, “sortable”=>false, “search”=>false));
$grid->setColProperty(“sho”, array(“label”=>” “, “width”=>25, “sortable”=>false, “search”=>false));
$grid->setColProperty(“edi”, array(“label”=>” “, “width”=>25, “sortable”=>false, “search”=>false));
$grid->setColProperty(“del”, array(“label”=>” “, “width”=>25, “sortable”=>false, “search”=>false));
$grid->setColProperty(“DemoAccount”, array(“label”=>”Demonstration Account”, “width”=>30, “hidden”=>true, “stype”=>”select”,”searchoptions”=>array(“searchhidden”=>true, “sopt”=>array(“eq”), “value”=>” : ;0:no;1:yes”)));
$grid->setColProperty(“LEAfter”, array(“label”=>”Licence ends on or after”, “width”=>30, “hidden”=>true, “searchoptions”=>array(“searchhidden”=>true, “sopt”=>array(“ge”))));
$grid->setColProperty(“LEBefore”, array(“label”=>”Licence ends on or before”, “width”=>30, “hidden”=>true, “searchoptions”=>array(“searchhidden”=>true, “sopt”=>array(“le”))));
$grid->setColProperty(“LicenceType”, array(“label”=>”Licence Type”, “width”=>30, “hidden”=>true, “stype”=>”select”, “searchoptions”=>array(“searchhidden”=>true, “sopt”=>array(“eq”), “value”=>”{$licType}”)));
$grid->setColProperty(“ParentOrganisationID”, array(“label”=>”Parent Organisation”, “width”=>30, “hidden”=>true, “stype”=>”select”, “searchoptions”=>array(“searchhidden”=>true, “sopt”=>array(“eq”), “value”=>”{$PO}”)));
$grid->setColProperty(“WebServiceID”, array(“label”=>”WebService”, “width”=>30, “hidden”=>true, “stype”=>”select”, “searchoptions”=>array(“searchhidden”=>true, “sopt”=>array(“eq”), “value”=>”{$WS}”)));
$grid->setColProperty(“CandidateEmail”, array(“label”=>”Candidate Email”, “width”=>30, “hidden”=>true, “searchoptions”=>array(“searchhidden”=>true, “sopt”=>array(“eq”))));
$grid->setColProperty(“UserName”, array(“label”=>”User Name”, “width”=>30, “hidden”=>true, “searchoptions”=>array(“searchhidden”=>true, “sopt”=>array(“eq”))));
$grid->setDatepicker(‘LEAfter’, array(“showOn”=>”focus”), true, true);
$grid->setDatepicker(‘LEBefore’, array(“showOn”=>”focus”), true, true);
$grid->setUserTime(“d/m/Y”);
$grid->SetUserDate(“d/m/Y”);
$grid->setDbDate(‘Y-m-d H:i:s’);
$grid->setDbTime(‘Y-m-d H:i:s’);
$grid->datearray = array(‘LEAfter’,’LEBefore’);
$loadevent = <<<LOADCOMPLETE
function(rowid){
var ids = jQuery(“#organisationlist”).getDataIDs();
for(var i=0;i<ids.length;i++){
var cl = ids;
var rowd = $(“#organisationlist”).getRowData(ids);
var a = rowd.Active;
var n = rowd.Notes;
var p = rowd.ParentOrganisationID;
if (a == 1) {
ac = ‘</ids>’;
} else {
ac = ‘</ids>’;
}
jQuery(“#organisationlist”).setRowData(ids,{act:ac});
if (n != ”) { // has notes
nt = ‘</ids>’;
} else {
nt = ” “;
}
jQuery(“#organisationlist”).setRowData(ids,{not:nt});
if (p == cl) { // is parent organisation
po = ‘</ids>’;
} else {
po = ” “;
}
jQuery(“#organisationlist”).setRowData(ids,{pog:po});
cp = ‘</ids>’;
jQuery(“#organisationlist”).setRowData(ids,{lic:cp});
de = ‘</ids>’;
jQuery(“#organisationlist”).setRowData(ids,{log:de});
bg = ‘</ids>’;
jQuery(“#organisationlist”).setRowData(ids,{deb:bg});
sp = ‘</ids>’;
jQuery(“#organisationlist”).setRowData(ids,{sup:sp});
rm = ‘</ids>’;
jQuery(“#organisationlist”).setRowData(ids,{sho:rm});
ed = ‘</ids>’;
jQuery(“#organisationlist”).setRowData(ids,{edi:ed});
dl = ‘</ids>’;
jQuery(“#organisationlist”).setRowData(ids,{del:dl});
}
}
LOADCOMPLETE;
$grid->setGridEvent(“loadComplete”,$loadevent);
// Enable navigator
$grid->navigator = true;
// Disable some actions
$grid->setNavOptions(‘navigator’, array(“excel”=>true,”add”=>false,”edit”=>false,”del”=>false,”view”=>false,”multipleSearch”=>true,”multipleGroup”=>true,”recreateFilter”=>true));
//$grid->setNavOptions(‘search’,array(“showQuery”=>true));
// Run the script
$grid->renderGrid(‘#organisationlist’,’#organisationpager’,true, null, null,true,true,true);
$conn = null;
What am I doing wrong please.
Hello,
Try to run the query from the log in the SQL console and in place of the ? set 1 – see the result
Kind Regards,
Will
Guriddo Support Team
Thanks Will.
I found the problem and have fixed this one. Need to include the LicenceTypeID from the organisation table in the select, hide the column but make it searchable.
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top