<!DOCTYPE html>
<html>
<head>
<title>Datatable: Loading with Connector</title>
<link rel="stylesheet" href="webix/codebase/webix.css" type="text/css" charset="utf-8">
<script src="webix/codebase/webix.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id='areaA'></div>
<div id='areaB'></div>
<script type="text/javascript" charset="utf-8"> webix.ui({
view:"datatable",
id:"datatable1",
container: "areaA",
columns:[
{ id:"id", name:"id", header:"#", css:"rank", width:50},
{ id:"rank", name:"rank", header:"Rank", css:"rank", width:50},
{ id:"title", name:"title", header:"Film title", width:200},
{ id:"cType", name:"cType", header:["Type Film", {content:"selectFilter"} ], sort:"string", width:200}
],
on:{
'onItemDblClick': function(id,e) {
showForm("frmEdit");
}
},
autoheight:true,
autowidth:true,
select:"row",
url: "tipologiche.php?cmd=test"
});
var form_edit = {
id: "form1",
view:"form",
container: "areaB",
elements:[
{ view:"text", id:"id", name:"id", label:"id"},
{ view:"text", id:"rank", name:"rank", label:"Rank"},
{ view:"text", id:"title", name:"title", label:"Title"},
{ view : "richselect", name:"idType",id:"idType", options:"tipologiche.php?cmd=type_films", label : "Type Film"},
{ view:"button", label:"Save" , type:"form", click:save_form },
{ view:"button", label:"Clear", click:"$$('form1').clear();" }
]
};
webix.ui({
view:"window",
id:"frmEdit",
move:true,
width:1300,
height:620,
position:"center",
modal:true,
head:{
view:"toolbar", margin:-4, cols:[
{ view:"label", label: "Element details" },
{ view:"icon", icon:"times-circle", click:"$$('frmEdit').hide();"}
]
},
body:webix.copy(form_edit)
});
$$('form1').bind($$('datatable1'));
function showForm(winId,node){
$$(winId).show(node);
$$(winId).getBody().focus();
}
function save_form(){
var row = $$("form1").getValues();
var s = { "cmd":"test", "table": "films", "row":row, "IdName":"id", "IdValue":row['id'] }
webix.ajax().post("update.php", s ,function(text) {
console.log(text);
});
$$("form1").save();
$$("frmEdit").hide();
};
</script> </body> </html>
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
include("include\\application.php");
$req = sizeof( $_POST ) > 0 ? $_POST : $_GET;
$cmd = $req['cmd'];
switch( $cmd ) {
case "test":
$sql = "SELECT * FROM films INNER JOIN type_films on films.idType = type_films.idType";
$ret = sqlExec($sql);
echo json_encode( $ret );
break;
case "type_films":
$sql = "SELECT idType as id, cType as value FROM type_films";
$ret = sqlExec($sql);
echo json_encode( $ret );
break;
case "owners":
$sql = "SELECT owner_name as id, owner_name as value FROM aisurvey_owner";
$ret = sqlExec($sql);
echo json_encode( $ret );
break;
case "profiles":
$sql = "SELECT IdProfilo as id, cProfilo as value FROM aisurvey_profiles";
$ret = sqlExec($sql);
echo json_encode( $ret );
break;
}
function sqlExec( $sql ) {
$ar = array();
$res = mysql_query( $sql );
while ($row = mysql_fetch_assoc($res)) {
$ar[] = $row;
}
return $ar;
}
?>
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
include("include/application.php");
$req = sizeof( $_POST ) > 0 ? $_POST : $_GET;
$cmd = $req['cmd'];
switch( $cmd ) {
case "owner":
$table = $req['table'];
$row = json_decode( $_POST['row'], true );
$IdName = $req['IdName'];
$IdValue= $req['IdValue'];
$ret = dbSql( $cmd, $table, $row, $IdName, $IdValue);
break;
case "test":
$table = $req['table'];
$row = json_decode( $_POST['row'], true );
unset($row['cType']);
$IdName = $req['IdName'];
$IdValue= $req['IdValue'];
$ret = dbSql( $cmd, $table, $row, $IdName, $IdValue);
break;
}
function dbSql( $cmd, $table, $ar, $idname, $idvalue ) {
$z = "";
foreach( $ar as $k => $v ) {
if( $k == "id" )
continue;
$z .= ($z != "" ) ? ",":"";
$z .= $k . "='" . mysql_real_escape_string($v) . "'";
}
$sql = sprintf( "UPDATE %s SET %s WHERE %s=%d", $table, $z, $idname, $idvalue );
$ret['sql'] = $sql;
$ret['ret'] = mysql_query( $sql );
$ret['ar'] = json_encode( $ar );
$ret['error'] = mysql_error();
$ret['insert_id'] = mysql_insert_id();
$ret['success'] = true;
if( mysql_error() != "" )
$ret['success'] = false;
return $ret;
}
?>
I’m sorry but I posted all my sample code . I have two problems : when I make the save , but the update does not update the Type Film on datatable and consequently do not update the filter of the column. I hope I was clear Thank you