7

in telerik extenstion to pass additional data to ajax request I used

function onDataBinding(e)
{
    e.data = {argument : 4};
}

where e was div cointainer with data object inside, How can I do this using kendo ? I tried the same but for Kendo e arqument is sth totally different.

kosnkov
  • 5,609
  • 13
  • 66
  • 107

5 Answers5

16

Finally i got the answer my own and it is :

$('#grid').data('kendoGrid').dataSource.read({name:value})
Itchydon
  • 2,572
  • 6
  • 19
  • 33
kosnkov
  • 5,609
  • 13
  • 66
  • 107
5

Try this:

  1. Add this to your grid read function or any CRUD operation:

    .Read(read => read.Action("ReadCompanyService", "Admin").Data("CompanyServiceFilter"))
    
  2. Add javascript:

    function CompanyServiceFilter()
    {
        return {
            company: $("#ServiceCompany").val()
        }
    } 
    
  3. In your controller:

    public ActionResult ReadCompanyService([DataSourceRequest]DataSourceRequest request, string company)
    {
        var gridList = repository.GetCompanyServiceRateList(company);
        return Json(gridList.ToDataSourceResult(request));
    }
    

Please note, only string type data is allowed to be passed on read, create, update and delete operations.

BSMP
  • 4,596
  • 8
  • 33
  • 44
Shazhad Ilyas
  • 1,183
  • 8
  • 14
5

Sorry for the terrible late at the party, but i've got some special cake that you may find tasty:

function readData()
{
    return {
        anagId: selectedItem.ID
    };
}

    $("#grid").kendoGrid({
        dataSource: {
            type: "ajax",
            transport: {
                read: {"url":"@Url.Action("RecordRead", "Tools")","data":readData} 
        }
       [ rest of the grid configuration]

I came across this code by inspecting the code generated by Kendo Asp.Net MVC helpers.

I don't know if this is a further implementation that didn't exist at the age of the post, but this way looks really the most flexible compared to the other answers that i saw. HTH

pizzaboy
  • 995
  • 1
  • 9
  • 20
3

If you want to pass some param to ajax request, you can use parameterMap configuration on your grid.

This will get passed on to your Ajax request.

parameterMap: function (options, operation) {
    if (operation === "read") {
        var selectedID = $("#SomeElement").val();
        return {ID: selectedID }
    }
    return kendo.stringify(options.models) ;
}
Henrique G. Abreu
  • 17,406
  • 3
  • 56
  • 65
RK911
  • 152
  • 1
  • 5
2

Try this:

.Read(read => read.Action("Controller", "Action")
    .Data(@<text>
        function() {                                            
            return {
                searchModel: DataFunctionName(),
                userName: '#=UserName#'
            }
        }
    </text>)
)

JS function

function DataFunctionName() {
    var searchModel = {
        Active: $("#activityMonitorIsActive").data('kendoDropDownList').value(),
        Login: $("#activityMonitorUsers").data('kendoComboBox').value()
    };
    return searchModel;
}
CarenRose
  • 1,266
  • 1
  • 12
  • 24
Shemeemsha R A
  • 1,416
  • 16
  • 22