Reputation: 355
I am a beginner in Kendo Ui and also JavaScript programming. I have a simple question how to submit the value from my checkbox to dataSource transport : read?
so "getMarketData.php" able to get "c1" value (active) and reload in the same page again.
Here I provide my code.
My checkbox :
<input type="checkbox" id="c1" name="checkbox1" class="k-checkbox" checked="checked" value="active" onclick="checkBox()">
My Javascript
<script>
$(function() {
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "/getMarketData.php",
type: "POST"
}
},
schema: {
model: {
id: "marketID"
}
}
});
});
function checkBox() {
var checkbox = document.getElementById("c1");
if (checkbox.checked == true) {
//pass "active" data
$("#grid").data("kendoGrid").refresh();
$("#grid").data("kendoGrid").dataSource.read();
} else {
if (checkBox.value == 'active') {
var x = 'inactive';
}
//pass "inactive" data
$("#grid").data("kendoGrid").refresh();
$("#grid").data("kendoGrid").dataSource.read();
}
}
Upvotes: 1
Views: 534
Reputation: 894
You can use transport.read.data property to pass additional data (more info: transport.read documentation).
Also, calling refresh() is not necessary.
Here's your edited example:
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: '/getMarketData.php',
type: 'POST',
data: function() {
return {
c1: document.getElementById('c1').checked,
};
},
},
},
schema: {
model: {
id: 'marketID',
},
},
});
function checkBox() {
$('#grid')
.data('kendoGrid')
.dataSource.read();
}
Upvotes: 1