datatable richselect bind

<!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

Hi,

The $$("form1").save(); call must push data back in the datatable, it will link column id to form field name. Currently, you have

id:“cType” in the datatable and name:“idType” in the form. You need to have the same value in both places.

To update filter, call $$("datatable1").refreshFilter("idType");

hi and thanks for the reply .
as you suggested , in the form I renamed the golf idType in cType.
But in this way on the datatable dblclick the richselect the form is not located on the item of the item on datatable but empty.
then when I click on save of the form in the datatable cell comes and saved the richselect Id and not the description .

Hi, check the next snippet

http://webix.com/snippet/d9c6b461

thanks maksim!

Datatable: Updating
	<script type="text/javascript" charset="utf-8">
	
	var types = new webix.DataCollection({ 
		data:"tipologiche.php?cmd=type_films" 
	});

	webix.ui({
		rows:[{
			view:"datatable",
			id:"datatable1",
			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", collection:types,	width:200}
			],
			on:{
				'onItemDblClick': function(id,e) {
					this.setCursor(id);  
					showForm("frmEdit");
				}
			},
			autoheight:true,
			autowidth:true,
			select:"row", 
			save: "server/datatable_save.php",
			url: "server/datatable.php"
		},
		{
			view:"toolbar", cols:[
				{},
				{ view:"button", label: 'Add',type:"form", width: 100, align: 'right'}
				]
			}
		]
	});
	
	
	var form_edit = {
        id: "form1",
        view:"form",
        elements:[
            { view:"text", id:"rank", name:"rank", label:"Rank"},
            { view:"text", id:"title", name:"title", label:"Title"},
			{ view : "richselect",  name:"cType",id:"cType", 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: "Edit" },
					{ view:"icon", icon:"times-circle",	click:"$$('frmEdit').hide();"}
				]
		},
        body:webix.copy(form_edit)
    });
	
	function save_form(){
		$$('form1').save();
		$$('frmEdit').hide();
	}
	
	function showForm(winId,node){
		$$(winId).show(node);
		$$(winId).getBody().focus();
	}
	
	
	$$('form1').bind($$('datatable1'));
	
	
	</script>
</body>

datatable.php

<?php error_reporting(E_ALL ^ E_DEPRECATED); //connect to database //$db = new SQLite3('../../../common/testdata.sqlite'); $conn = mysql_connect("localhost", "root", ""); $db = mysql_select_db( "aiviewgroup", $conn ); $str = ""; //select data $sql = "SELECT * FROM films INNER JOIN type_films on films.idType = type_films.idType"; $res = mysql_query( $sql ); //convert data to json $data = array(); while ($rec = mysql_fetch_assoc($res)) $data[] = $rec; //output json echo json_encode($data); ?>

why the collection is not charging ? where am I wrong ?
Thank you