This is a migrated thread and some comments may be shown as answers.

Grid problem

2 Answers 156 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kevin
Top achievements
Rank 1
kevin asked on 27 Aug 2012, 01:24 AM
Hi everyone!
First i congratulate the team of Kendo UI for this tool so good for web developers, well let's get

I have a problem with a Grid with inline editing option enabled, the problem is that the button for add a new row doesn't work and i don't know what is the way for add,edit and delete rows, also i want to know what the variable that receives php from grid.

thanks in advanced

This is  the code

 
$(function() {
kendo.culture("es-ES");
var grid = $("#grid").kendoGrid({dataSource: {transport: {read: "datos_grid.php",create: {url: "datos_grid.php",type: "POST"},parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)}
}
}},schema: {data: "data",total: function(result) {
var data = this.data(result);
return data ? data.length : 0
},model: {id: "id",fields: {id: {validation: {required: true}},user_id: {validation: {required: true}},purchase_date: {validation: {required: true},type: "date"}}}},pageSize: 5,autoSync: true,batch: true},columns: [{title: "ID",field: "id",type: "text"}, {title: "Id Usuario",field: "user_id",type: "text"}, {title: "Fecha",field: "purchase_date",format: "{0:dd/MM/yyyy}"}, {command: ["edit", "destroy"],title: " ",width: "210px"}],pageable: {refresh: true,pageSizes: 5},toolbar: ["create", {template: kendo.template($("#template").html())}],editable: "inline"});
$("#category").keyup(function() {
var value = $(this).val();
if (value) {
grid.data("kendoGrid").dataSource.filter({logic: "or",filters: [{field: "id",operator: "contains",value: value}, {field: "user_id",operator: "contains",value: value}]})
} else {
grid.data("kendoGrid").dataSource.filter({})
}
})
});

2 Answers, 1 is accepted

Sort by
0
kevin
Top achievements
Rank 1
answered on 27 Aug 2012, 02:01 AM
i already found the problem is the property autoSync that must not enabled
0
kevin
Top achievements
Rank 1
answered on 27 Aug 2012, 05:47 PM
Hi again jajajajaja

well I have a new problem concerning foreign keys,
i seen the page of foreign key of demos de kendo ui grid and I followed all the steps and still not working.

Really i dont understand why not working

my code:
$(function() {
    kendo.culture("es-ES");
  var categorias = new kendo.data.DataSource({
        transport:{ read:"categorias_usuarios.php"},schema: {data: "datos",
                    model:{
                        id:"value",
                        fields:{text:{type:"string"}}
 
                    }
                }
 
    });
    var datos= new kendo.data.DataSource(
        {transport: {read: "datos_grid.php",create: {url: "create_data.php",type: "POST"},update:{ url: "update_data.php", type:"POST"}, destroy:{ url: "delete_data.php", type:"POST"},parameterMap: function(options, operation) {
                    if (operation !== "read" && options.models) {
                        return {models: kendo.stringify(options.models)}
                    }
                }},error: function(e) {
            alert(e.responseText);
        },schema: {data: "data",total: function(result) {
                    var data = this.data(result);
                    return data ? data.length : 0
                },model: {id: "cod_maestros",fields: {id: {nullable:true,editable:false},nombres_usuarios: {validation: {required: true}},apellidos_usuarios: {validation: {required: true}},cod_nivel_usuario:{field:"cod_nivel_usuario"}}},pageSize: 5,batch: true}}
    );
    var grid = $("#grid").kendoGrid({dataSource:datos ,columns: [{title: "Nombres del Usuario",field: "nombres_usuarios",type: "text"}, {title: "Apellidos del Usuario",field: "apellidos_usuarios",type: "text"}, {title: "Nivel", field: "cod_nivel_usuario",values:categorias}, {command: ["edit", "destroy"],title: " ",width: "210px"}],pageable: {refresh: true,pageSizes: 5},toolbar:[{name:"create",text:"Agregar nuevo registro"}, {template: kendo.template($("#template").html())}],editable: "popup"});
    $("#category").keyup(function() {
        var value = $(this).val();
        if (value) {
            grid.data("kendoGrid").dataSource.filter({logic: "or",filters: [{field: "nombres_usuarios",operator: "contains",value: value}, {field: "apellidos_usuarios",operator: "contains",value: value}]})
        } else {
            grid.data("kendoGrid").dataSource.filter({})
        }
    });
     
});

and the code of categorias_usuarios.php
$link = mysql_pconnect("localhost", "root", "") or die("Unable To Connect To Database Server");
     mysql_select_db("expo_2012") or die("Unable To Connect To cmi_test");
     $rs = mysql_query("select cod_nivel_usuario,nivel FROM nivel_usuario where nivel !='Administrador'");
     $arr=array();
    while($obj = mysql_fetch_assoc($rs))
        {
          $arr[]=$obj;
        }
        foreach ($arr as $k => $v) {
   unset ($arr[$k]['cod_nivel_usuario']);
   unset ($arr[$k]['nivel']);
   $new_key1 = 'value';
    $new_key2 = 'text';
$arr[$k][$new_key1] =(int)$v['cod_nivel_usuario'];
$arr[$k][$new_key2]=$v['nivel'];
}
         
      header("Content-type: application/json");
  echo "{\"data\":" .json_encode($arr). "}";

and datos_grid.php

$link = mysql_pconnect("localhost", "root", "") or die("Unable To Connect To Database Server");
    mysql_select_db("expo_2012") or die("Unable To Connect To cmi_test");
    $rs = mysql_query("SELECT nombres_usuarios,apellidos_usuarios,cod_nivel_usuario,cod_maestros FROM usuarios_normales
     where cod_maestros != 'Admin'");
    $arr=array();
    $i=0;
   while($obj = mysql_fetch_assoc($rs))
       {
         $arr[]=$obj;
         $arr[$i]['cod_nivel_usuario']=(int)$arr[$i]['cod_nivel_usuario'];
          $i++;
       }
 
        
     header("Content-type: application/json");
 echo "{\"data\":" .json_encode($arr). "}";
Tags
Grid
Asked by
kevin
Top achievements
Rank 1
Answers by
kevin
Top achievements
Rank 1
Share this question
or