Kendo grid how to pass additional parameter from java script

20,965

Solution 1

Finally i got the answer my own and it is :

$('#grid').data('kendoGrid').dataSource.read({name:value})

Solution 2

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

Solution 3

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.

Solution 4

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) ;
}

Solution 5

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;
}
Share:
20,965

Related videos on Youtube

kosnkov
Author by

kosnkov

Updated on August 13, 2020

Comments

  • kosnkov
    kosnkov almost 4 years

    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
    kosnkov over 10 years
    but I am asking how to do it from java script, how to pass it using javascript if I have this var grid.
  • Shazhad Ilyas
    Shazhad Ilyas over 10 years
    to me to understand fully please post the code and describe what you are trying to achieve....
  • NiallMitch14
    NiallMitch14 almost 4 years
    Works perfectly but Read() is not a function. It should be read() instead.