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

Inline Grid combobox get searchtextvalue for serverFiltering

2 Answers 42 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Merve
Top achievements
Rank 1
Veteran
Merve asked on 24 Aug 2020, 05:14 PM

This my Editor

function userNameAutoCompleteEditor(container) {
 
    $('<input id="UserId" name="UserId">')
        .appendTo(container)
        .kendoComboBox({
            autoBind: false,
            dataTextField: "UserName",
            dataValueField: "UserId",
            filter: "contains",
            minLength: 3,
            valuePrimitive: true,
            dataSource: new kendo.data.DataSource({            
                contentType: "application/json; charset=utf-8",
                serverFiltering: true,
                transport: {
                    read: {                       
                        url: '../Warehouse/SearchUser' ,
                        data: function () {
                            debugger;
                            UserSearcText:"asd"
 
                        }
                        
                    }
                },
            }),
        });
}

 

///Mvar grid = new BaseGrid('grdWarehouse_OnWarehouseUserRelation');
    grid._batch = false;
    grid._dataSourceAutoSync = false;
    grid._toolbar = ['create'/*, 'save', 'cancel'*/];
    grid._editable = {
        mode: "inline",
        create: true,
        update: true,
        destroy: true,

    };
    grid._autoBind = false;
    grid._schemaMethod = {
        model: {
            id: 'Id',
            fields: {
                Id: { editable: false },
                //User: { defaultValue: { UserId: '', UserName: '' } },
                
            }
        }
    };
    grid._columns.push(grid.GridColumn('Id', null, '200px', null, null, null, null, null, null, null, true));
    //grid._columns.push(grid.GridColumn('User', 'User', '200px', null, "#=User.UserName#", null, null, null, null, null, null, null, null, null, userNameAutoCompleteEditor));
    grid._columns.push(grid.GridColumn('UserId', 'User', '200px', null,'#=modelName(this)#', null, null, null, null, null, null, null, null, null, userNameAutoCompleteEditor));
    grid._columns.push(grid.GridColumn(null, '&nbsp;', '200px', { style: 'text-align:right' }, null, null, null, null, null, null, null, null, null, ['edit', 'destroy']));

    grid._cancelMethod = function (e) {
        var uid = $("#grdWarehouse_OnWarehouseUserRelation").data("kendoGrid").dataItem($(e.container).closest("tr")).uid
        dataSource = $("#grdWarehouse_OnWarehouseUserRelation").data("kendoGrid").dataSource
        var item = dataSource.getByUid(uid);
        dataSource.cancelChanges(item);
    };

//My problem  ı need filter text to send the controller.But  I cant catch searc text CAN YOU HELP ME!!!!??????????

This my grid

01.var grid = new BaseGrid('grdWarehouse_OnWarehouseUserRelation');
02.    grid._batch = false;
03.    grid._dataSourceAutoSync = false;
04.    grid._toolbar = ['create'/*, 'save', 'cancel'*/];
05.    grid._editable = {
06.        mode: "inline",
07.        create: true,
08.        update: true,
09.        destroy: true,
10. 
11.    };
12.    grid._autoBind = false;
13.    grid._schemaMethod = {
14.        model: {
15.            id: 'Id',
16.            fields: {
17.                Id: { editable: false },
18.                //User: { defaultValue: { UserId: '', UserName: '' } },
19.                 
20.            }
21.        }
22.    };
23.    grid._columns.push(grid.GridColumn('Id', null, '200px', null, null, null, null, null, null, null, true));
24.    //grid._columns.push(grid.GridColumn('User', 'User', '200px', null, "#=User.UserName#", null, null, null, null, null, null, null, null, null, userNameAutoCompleteEditor));
25.    grid._columns.push(grid.GridColumn('UserId', 'User', '200px', null,'#=modelName(this)#', null, null, null, null, null, null, null, null, null, userNameAutoCompleteEditor));
26.    grid._columns.push(grid.GridColumn(null, ' ', '200px', { style: 'text-align:right' }, null, null, null, null, null, null, null, null, null, ['edit', 'destroy']));
27. 
28.    grid._cancelMethod = function (e) {
29.        var uid = $("#grdWarehouse_OnWarehouseUserRelation").data("kendoGrid").dataItem($(e.container).closest("tr")).uid
30.        dataSource = $("#grdWarehouse_OnWarehouseUserRelation").data("kendoGrid").dataSource
31.        var item = dataSource.getByUid(uid);
32.        dataSource.cancelChanges(item);
33.    };

 

 

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Aleksandar
Telerik team
answered on 26 Aug 2020, 12:54 PM
the filter value from the HTTP Context:

Hello Merve,

If my understanding is correct, and as discussed in the other forum topic on the same topic, you would like to get the user input in AutoComplete Editor in the Action method that filters the data on the server-side.

When the AutoComplete is configured to use server filtering the filter is sent to the server following jQuery conventions

filter[filters][0][value]: Jane //value that the user has entered
filter[filters][0][field]: UserName
filter[filters][0][operator]: contains
filter[logic]: and

In the Controller, you can get the filter value from the HTTP Context:

var userInput = HttpContext.Request.QueryString.Get(0);

So the action method could look something like the below:

public JsonResult SearchUser()
{
     var userInput = HttpContext.Request.QueryString.Get(0);      
     var users = GetAllUsers(); 
     
     if (!string.IsNullOrEmpty(userInput))
     {
         users = users.Where(u => u.UserName.Contains(userInput));
      }

     return Json(users.ToList());           
}

Regards,
Aleksandar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Merve
Top achievements
Rank 1
Veteran
answered on 28 Aug 2020, 06:51 AM

ı solved my problem this my code ...

 

01.function userNameEditor(container, options) {
02.    debugger;
03.    var gridDataSource = new kendo.data.DataSource({
04.        transport: {
05.            read: {
06.                url: '../Warehouse/SearchUser',
07.                dataType: "json"
08.            },
09.            success: function(e) {
10.                debugger;
11.            },
12.            error: function (e) {
13.                debugger;
14.            }
15.        }
16.    });
17.        var cmb=$('<input name="' + options.field + '"/>')
18.        .appendTo(container)
19.        .kendoComboBox({
20.            autoBind: false,
21.            dataTextField: "UserFullName",
22.            dataValueField: "Id",
23.            filter: "contains",
24.            minLength: 3,
25.            dataSource: gridDataSource,
26.            filtering: function (e) {
27.                
28.                var filter = e.filter;
29.                gridDataSource.read({ userSearchText: filter.value });
30.                //dataSource.filter({ userSearchText: filter.value });
31.            },
32.            dataBound: function (e) {
33.                debugger;
34.                var equipmentData = e.sender.dataSource.data();
35. 
36. 
37.                        $.each(equipmentData, function (index, selectedEquipmentData) {
38.                                var dataItem = e.sender.dataSource.at(index);
39. 
40.                        });
41.            },
42.            select: function(e) {
43.                debugger;
44.                this.refresh();
45.            },
46.            complete: function(e) {
47.                debugger;
48.            },
49.            error: function(e) {
50.                debugger;
51.            }
52.        }).data('kendoComboBox');
53.    cmb.refresh();
54.    debugger;
55.        //.kendoComboBox({
56.        //    autoBind: false,
57.        //    dataTextField: "NameSurname",
58.        //    dataValueField: "Id",
59.        //    filter: "contains",
60.        //    minLength: 3,
61.        //    dataSource: dataSource,
62.        //    filtering: function (e) {
63.        //        debugger;
64.        //        var filter = e.filter;
65.        //        //dataSource.read({ userSearchText: filter.value });
66.        //        dataSource.filter({ userSearchText: filter.value })
67.        //    }
68.        //});
69.};
Tags
ComboBox
Asked by
Merve
Top achievements
Rank 1
Veteran
Answers by
Aleksandar
Telerik team
Merve
Top achievements
Rank 1
Veteran
Share this question
or