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

I can filter my grid

1 Answer 40 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eduardo
Top achievements
Rank 1
Eduardo asked on 30 Apr 2013, 06:57 PM
Hello,

Im trying to create a custome filter but this never pass to my controller some field that have the filter name

I create a function that initialize the Grid
function KendoUIGrid(config)
{
    var grid = $("#" + config.id);
 
    grid.kendoGrid({
        columns: config.columns,
        dataSource: {
            transport: {
                read: {
                    url: config.url,
                    dataType: "JSON",
                    type: "POST",
                    data: {
                        action: 'read'
                    }
                },
                //destroy: {
                //    url: config.url,
                //    dataType: "JSON",
                //    type: "POST",
                //    data: {
                //        action: 'destroy'
                //    }
                //},
                //update: {
                //    url: config.url,
                //    dataType: "JSON",
                //    type: "POST",
                //    data: {
                //        action: 'update'
                //    }
                //},
                //create: {
                //    url: config.url,
                //    dataType: "JSON",
                //    type: "POST",
                //    data: {
                //        action: 'create'
                //    }
                //},
                parameterMap: function (options) {
                    var result = {
                        page: options.page,
                        pageSize: options.pageSize,
                        skip: options.skip,
                        orderBy: '',
                        take: options.take,
                        pi: options.page == 1 ? 1 : options.skip + 1,
                        pf: options.skip + options.take,
                        action: options.action
                    };
 
                    if (options.sort != undefined) {
                        if (options.sort[0] != undefined) {
                            result.orderBy = options.sort != undefined ? options.sort[0]['field'] + ' ' + options.sort[0]['dir'] : '';
                        } else {
                            result.orderBy = 1;
                        }
                    }
 
                    return result;
                }
            },
            schema: {
                total: "total",
                data: "data"
            },
            pageSize: 15,
            serverSorting: true,
            serverPaging: true,
            severFiltering: true
        },
        sortable: true,
        resizable: true,
        pageable: {
            numeric: false,
            input: true
        },
        selectable: true
    });
Its ok, work fine but i can send filters ... my logic is create a filter and under the filter show the grid
I have this HTML

<h2>Proveedores</h2>
<div class="box k-shadow">
    <div id="grid">
        <div class="k-block">
            <div class="k-header">Filtro de búsqueda</div>
            <table>
                <tr>
                    <td>
                        <input type="text" name="nombre" placeholder="Ingrese el nombre del proveedor" class="k-textbox" />
                    </td>
                    <td style="width:100px;">
                        <select>
                            <option>Activo</option>
                            <option>Inactivo</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <button class="k-button">Limpiar</button>
                        <button id="btnFiltrar" class="k-button">Filtrar</button>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div
And for initialize the grid i only need to use this
$(document).ready(function () {
    var config =
    {
        id: 'grid',
        url: BaseUrl('mantenimiento/ProveedorGrid'),
        columns: [
            { field: "id", title: "id", width: 50, hidden: true },
            { field: "nombre", title: "Nombre" },
            {
                command:
                [
                    {template: KendoUILinkButton(BaseUrl('mantenimiento/proveedor'), 'edit')},
                    {template: KendoUILinkButton(BaseUrl('mantenimiento/ProveedorGrid'), 'delete')}
                ],
                width: 88
            }
        ]
    };
 
    KendoUIGrid(config);
 
    $("#btnFiltrar").click(function () {
        $("#grid")
            .data("kendoGrid")
            .dataSource.filter({
                filters: [
                  { field: "nombre", operator: "startswith", value: "Paul" }
                ]
            });
    })
})

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 01 May 2013, 07:11 AM
Hello,

 You have set the parameterMap but you never return the filter. The result of the parameterMap is passed to the server. You need to include the filter (passed as options.filter) in the result. For more information check the documentation of the parameterMap option.

Kind regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Eduardo
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or