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

Grid filter

8 Answers 275 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JC
Top achievements
Rank 1
JC asked on 05 Feb 2013, 10:29 AM
Hi kendo users!

I have a problem with the filter on this grid:

grid declaration:
                $("#grid2").kendoGrid({
                    dataSource: {
                        transport: {
                            read: "datos/CargarTipo_Impresion_s.php" //php file with mysql sentence
                        },
                        batch: true,
                        schema: {
                            model: {
                                id: "notipoimpresion",
                                fields: {
                                    notipoimpresion: { type: "number" },
                                    descripcion: { type: "string" },
                                    nogrupo: { type: "number" },
                                }
                            }
                        },
                        //send notipoimpresion like parameter to the page : CargarTipo_Impresion_s.php
                        serverFiltering: true,
                        //filter: { field: "notipoimpresion", operator: "eq", value: "1,2" }, // with this filter is ok, show data
                        //filter: { field: "notipoimpresion", operator: "eq", value: 2 }, //with this filter is ok , show data
                        //filter: { field: "notipoimpresion", operator: "eq", value: '1,2' }, //with this filter is ok, show data

                        filter: { field: "notipoimpresion", operator: "eq", value: value_codigos_tipo_impresion }, //with this filter doesn´t show data
                        //value_codigos_tipo_impresion, can have this values: "1" or "1,2" or "1,2,4", etc.
                       //value_codigos_tipo_impresion, receive the value from a form text

in CargarTipo_Impresion_s.php use this:
$codigos_tipo_impresion = mysql_real_escape_string($_REQUEST["filter"]["filters"][0]["value"]);
and the execute a mysql sentence

Could someone tell me, why doesn´t make the filter ? or what is wrong?

Thanks
JC

8 Answers, 1 is accepted

Sort by
0
JC
Top achievements
Rank 1
answered on 05 Feb 2013, 10:36 AM
I forget this:
In other example with php variable works!

filter: { field: "notipoimpresion", operator: "eq", value:"<?php echo $var_codigos_tipo_impresion; ?>" },

when $var_codigos_tipo_impresion: can have values: "1", "1,2", "1,2,3·, etc...

JC
0
Alexander Valchev
Telerik team
answered on 07 Feb 2013, 11:49 AM
Hello,

I am afraid that your question is a bit unclear. What is the exact value of value_codigos_tipo_impresion variable in the example where it does not work? Field notipoimpresion is of type number, how do you expect to contain a value "1,2,4"? This is not a valid number. On the other hand you said that this works when the value is hard coded.

Could you please explain in more details? Is it possible to provide an example?

Regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
JC
Top achievements
Rank 1
answered on 07 Feb 2013, 12:57 PM
Hello,
Try to explain my problem:
I want to filter a grid with a input value form with id="value_codigos_tipo_impresion"
the values can be "1,2,3..."

I know the field "notipoimpresion" is number, but in other example my code works with php parameter:
example: filter: { field: "notipoimpresion", operator: "eq", value:"<?php echo $var_codigos_tipo_impresion; ?>" },

I think... if worked in php, use the same code on javascript, for that reason use the same line of code.

more information:
this is the code I have in the file: CargarTipo_Impresion_s.php

        $codigos = mysql_real_escape_string($_REQUEST["filter"]["filters"][0]["value"]);
        $arr = array();
        $rs = mysql_query("SELECT     
                                A.notipoimpresion,
                                A.descripcion,
                                A.nogrupo
                        FROM     tipo_impresion as A
                        WHERE    A.notipoimpresion in (".$codigos.")
                        ORDER     BY A.notipoimpresion");

example:  this sentence execute in MySql : A.notipoimpresion in ("1,2,3")

How I can make this filter? or I need to change everything?

Thank you for your help :D
0
JC
Top achievements
Rank 1
answered on 08 Feb 2013, 12:57 PM
Hello
this is a small example, of what I try to do :

http://jsfiddle.net/jcpaquot/Fg4SV/2/

I need to filter by one value, who take value from a grid or a form, and then open a popup window
who contain one grid who show data filter of the value received.
Is this example don´t use my database and don` t use a php, but is something like that.

The original idea is send a value string:  "1,2,3" and filter by one field who is a field number (notipoimpresion)
and php I try to make this:

        $rs = mysql_query("SELECT     
                                A.notipoimpresion,
                                A.descripcion,
                                A.nogrupo
                        FROM     tipo_impresion as A
                        WHERE    A.notipoimpresion in (".$codigos.")
                        ORDER     BY A.notipoimpresion");

where $codigos will be : "1,2,3"  or "1" or "1,4" ....

Another idea to make this?

Thank you for advance

JC

0
Accepted
Alexander Valchev
Telerik team
answered on 11 Feb 2013, 09:48 AM
Hi JC,

Thank you for the provided example. I noticed the following issues:
  • incorrect syntax: serverFiltering and filter are options of the DataSource, not the Grid. By the way the service that you use in the fiddle does not work with server filtering.
  • you are not filtering the DataSource of the second grid at all - in order to do that you should use filter method of the dataSource. Filter option defined in the DataSource's configuration will be evaluated only once during the initialization. 
    dataSource: {
      pageSize: 5,
      transport: {
        read: {
          dataType: "jsonp"
        }
      },
      //this will set initial filter
      //if you want to filter at latest point you should use
      //grid.dataSource.filter({<filter object>});
      filter: {
          field: "ProductID",
          operator: "eq",
          value: value_ProductID
      }
    },


  • title of the window will be set only once (same case as above).
    title: "window popup, grid filter by ProductID : " + value_ProductID,
    //if you want to change the title at runtime you should the title method

    Docs: title method

  •  please do not mix the version of KendoUI JavaScript and CSS resources.

I hope this information will help. Please review those issues and let me know if you have any further questions.

Regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
JC
Top achievements
Rank 1
answered on 11 Feb 2013, 01:12 PM
Hi Alexander !

Thank you for your answer.
I changed my code and works perfectly in my local test.
if I open window popup its grid assigned made the filter by ProductID, showing only the row selected and the title of the window show ProductID and ProductName, but does not do the fiddle example.

<href="http://jsfiddle.net/jcpaquot/vJTwF/2/">
What is wrong?
Another question:
what do you want to say with : "do not mix the version of KendoUI JavaScript and CSS resources" ?

JC
0
Accepted
Alexander Valchev
Telerik team
answered on 13 Feb 2013, 10:34 AM
Hi JC,

I am glad to hear that the suggested approach fitted in your local project.
jsFiddle example is not working due to the JavaScript error thrown in PasarDetalleContacto() function. In the console I see: 
form1.ProductID.value = value_ProductID;
>> Uncaught TypeError: Cannot set property 'value' of undefined

As a result the dataSource of the child grid is not being filtered. Please review the custom logic in your example.

Regarding what do you want to say with : "do not mix the version of KendoUI JavaScript and CSS resources"?
The example uses KendoUI CSS v2012.2.913 and JavaScript file v2012.3.1114. You should use CSS and JavaScript files from the same build. Preferably the latest one.

Regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
JC
Top achievements
Rank 1
answered on 13 Feb 2013, 10:53 AM
This example work perfectly!

Code corrected and version KendoUI CSS and JavaScript : v2012.3.1114

http://jsfiddle.net/jcpaquot/vJTwF/6/

Thank you Alexander!

JC
Tags
Grid
Asked by
JC
Top achievements
Rank 1
Answers by
JC
Top achievements
Rank 1
Alexander Valchev
Telerik team
Share this question
or