Reputation: 2214
How can i send extra parameters on my GRID POST.
This is my tranport config:
transport: {
read: {
dataType: "json",
url: "/user/list",
type: "POST"
}
}
I need to send a dynamic extra information ( especial filters XD). I will set a script variable before any submit on grid.
Any Help?
Upvotes: 2
Views: 6521
Reputation: 628
Here is another alternative to send parameters to the AJAX call, and also to log the Request and Response.
read: function (options) {
var jsonData = {
"ID": $('#ID').val(),
"ObjectType": $('#dropObjectType :selected').val()
};
console.log("REQ: " + JSON.stringify(jsonData));
$.ajax({
type: "POST",
url: "/api/internal/SomeService",
data: jsonData,
success: function (result) {
console.log("RES: " + JSON.parse(JSON.stringify(result)));
You can also send the above jsonData
in this way:
$("#grid").data("kendoGrid").dataSource.read(jsonData);
And assign it to the data:
(and log it):
read: function (options) {
console.log("REQ: " + JSON.stringify(options.data));
$.ajax({
type: "POST",
url: "/api/internal/SomeService",
data: options.data,
Upvotes: 0
Reputation: 1267
You can add extra parameters using Data("addParameter")
@(Html.Kendo().Grid<Project.Models.UserModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(item => item.UserId).Title("UserId").Width(100);
columns.Bound(item => item.UserName).Title("UserName").Width(200);
})
.Sortable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(5)
.Read(read => read.Action("list", "user").Data("addParameter"))
)
<script>
function addParameter()
{
return {
UserId: 10 //Your value here
};
}
</script>
Upvotes: 0
Reputation: 20233
Question is discussed multiple times on the internet. You should use the Data function. Here is even more information. You can also pass the parameters directly to the read method of the dataSource.
$('#myGrid').data().kendoGrid.dataSource.read({foo:42})
Upvotes: 10