Home › Forums › Guriddo Suito PHP › Entry formula on input
Tagged: formula input jqsuite
Hi,
How to make our input can accept formula ? I’ve tried in old jqgrid and it works without any setting.. but I can’t do it on JqSuite PHP…
https://s19.postimg.org/w54c6hkoz/Selection_209.jpg
Thank you and Regards,
Hello,
Could you please let us know where and how you do this. If previously you use jqGrid JavaScript, then you can do this in PHP too – just let us know the JavaScript way.
Kind Regards,
Will
Guriddo Support Team
Hi,
Maybe you can see my demo using jqGrid PHP and jqSuite PHP… I love jqSuite cause it cut my production time a lot. There’s nothing special coding both of them.
jqgrid code :
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
$karyawanid = $_POST['KARYAWANID']; if (empty($karyawanid)&& $karyawanid!= 0) {$karyawanid = 'null'; } $tgl = "'$_POST[TGL]'"; if (empty($_POST[TGL])) {$tgl = 'null'; } $desc = $_POST['DESC']; if (empty($desc)&& $desc!= 0) {$desc = 'null'; } $salary = $_POST['SALARY']; if (empty($salary)) {$salary = 'null'; } $action = $_REQUEST['oper']; if( $_REQUEST['export']=='excel') $action = 'export'; if (empty($action) && empty($_POST['id'])) {$action = 'load';} else if (empty($action)) {$action = 'edit'; } $pos = strpos($wh, "TGL"); if ($action=='del') { $sql = "Delete from COBA where KARYAWANID = ".$id; $stmt = $connPDO->query($sql); if(!$stmt){$error = $connPDO->errorInfo(); $_SESSION[message]=$error[2];} } else if ($action == 'add') { $sql = "Insert into COBA (KARYAWANID, TGL, DESC, SALARY) values ($id, $tgl, $desc, $salary)"; $stmt = $connPDO->query($sql); if(!$stmt){$error = $connPDO->errorInfo(); $_SESSION[message]=$error[2];} } else if ($action == 'edit') { $sql = "update COBA set tgl = $tgl ,salary = $salary where KARYAWANID = $id"; $stmt = $connPDO->query($sql); if(!$stmt){$error = $connPDO->errorInfo(); $_SESSION[message]=$error[2];} } else if ($action=='load') { $i=0; $sql = "select k.nama, c.tgl, c.karyawanid, c.desc, c.salary from coba c left join karyawan k on c.karyawanid = k.karyawanid where 1=1 $wh order by $sidx $sord" ; $_SESSION['sqlKaryawan'] = $sql; $stmt = $connPDO->query($sql); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); $i=0; foreach ($rows as $row) { $responce->rows[$i]['id']=$row[KARYAWANID]; $responce->rows[$i]['cell']=array($row[NAMA], $row[TGL] ,$row[DESC], $row[SALARY] ,$row[KARYAWANID]); $i++; } if($_SESSION[message]) {$responce->userdata['message'] = $_SESSION[message];unset($_SESSION['message']);} echo json_encode($responce); |
jqSuite PHP code :
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
..... $grid->dataType = 'json'; $grid->setPrimaryKeyId("COBAID"); $grid->setColModel(); $grid->table = $table; $grid->setUrl('coba2_.php'); $grid->setDbTime('Y-m-d'); $grid->setDbDate('Y-m-d'); $grid->setUserDate('Y-m-d'); $grid->setUserTime('Y-m-d'); $grid->setColProperty("COBAID", array("label"=>"ID", "hidden"=>true)); $grid->setColProperty('TGL', array("formatter" => "date", "formatoptions" => array("srcformat" => "Y-m-d H:i:s", "newformat" => "Y-m-d"), "editoptions" => array("dataInit" => "js:function(elm){ jQuery(elm).datepicker({dateFormat:'yy-m-d'}); jQuery('.ui-datepicker').css({'zIndex':'1200','font-size':'75%'});}") )); $grid->setColProperty("KARYAWANID", array("label"=>"KaryawanId (should be hidden)","hidden"=>true, "editable"=>true, "searchoptions"=>array("sopt"=>array('cn')))); $grid->setColProperty("NAMA", array("label"=>"Name", "searchoptions"=>array("sopt"=>array('cn')))); $grid->setAutocomplete("NAMA","#KARYAWANID","SELECT kk.NAMA, kk.NAMA, kk.KARYAWANID FROM KARYAWAN kk WHERE NAMA LIKE upper(?)" . " ORDER BY kk.NAMA ",null, true, true); $grid->setColProperty("DESC", array("label"=>"Description", "width"=>85, "searchoptions"=>array("sopt"=>array('cn')))); $grid->setColProperty("SALARY", array("label"=>"Salary","formatter"=>"number", "summaryType"=>"sum", "align"=>"right","search"=>false, "width"=>85,"searchoptions"=>array("sopt"=>array("eq","gt","lt")))); $grid->setGridOptions(array("rowNum"=>99999,"rowList"=>array(10,20,30),"sortname"=>"TGL", "height"=>'150', "caption"=>"Date on First Column (popup not shown)", "footerrow"=>true, "userDataOnFooter"=>true, "grouping"=>false, "shrinkToFit"=>false, "width"=>600 )); $grid->ignoreCaseSearch = true; $grid->setSearchOptions( array ( "sqlfunc" => "UPPER", "phpfunc" => "strtoupper" )); $grid->toolbarfilter = true; $grid->navigator = true; $grid->setNavOptions('navigator', array("excel"=>false,"add"=>true,"edit"=>true,"del"=>true,"view"=>true)); $_POST = array_map("strtoupper", $_POST); $grid->renderGrid('#grid2','#pager2',true, null, null, true,true); |
I’ve tried to entry both :
would be loved to if it can be done with jqSuite PHP.
Regards,
Ari Adrianto
Hello,
It depend where you want to put this logic – server side or client side.
I think that one possible solution is toy use a javascript formula parser something like this one
The idea is to bind a change event to this field using dataInit function and maybe it is better to use two fields one for the formula another for result, but I think it can be done with one field too.
Kind Regards,
Will
Guriddo Support Team
Hi,
It’s working by adding math function.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$calcs = <<< CALCS function(postdata) { postdata['SALARY'] = math.eval(postdata['SALARY']); return postdata; } CALCS; $grid->setNavEvent("edit", "serializeEditData", $calcs); $grid->setNavEvent("insert", "serializeEditData", $calcs); |
okay… thank you…
But I think I will change any formatter number with this math function… I’m the lazy one… LOL…
Thank you for your support
Hello,
Thank you for the feedback. We don’t try this, so it is a good that you post this for the other users.
Thank you.
Kind Regards
Will
Guriddo Support Team
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top
[/url]