copy all data from Kendo UI Grid Export to Excel - kendo-ui

I have a KendoUi Grid with excel, PDF inbuilt toolbar template, I am filling the kendoGrid with ajax request for each page request I am doing ajax call to server and binding data to my grid.y because my grid have 100,000 records(to increase performence).so when I use all pages is true property it's not Exporting all records.
var grid = $('#NewLeadsGrid').data("kendoGrid")
var newdataSource = new kendo.data.DataSource({
transport: {
read: function (options) {
$.ajax({
url: '/Reports/NewLeadsList',
contentType: "application/json; charset=utf-8",
dataType : "json",
data: JSON.stringify({
LifecycleStage: selfNewLeads.LifecycleStage(),
ShowTop: $('#NewLeadsGrid').data("kendoGrid").dataSource.pageSize(),
Filters: selfNewLeads.Filters(),
CustomStartDate: selfNewLeads.CustomStartDate(),
CustomEndDate: selfNewLeads.CustomEndDate(),
PageNumber: $('#NewLeadsGrid').data("kendoGrid").dataSource.page(),
CustomPredicateScript: selfNewLeads.CustomPredicateScript()
}),
type: 'post',
success: function (result) {
options.success(result);
}
});
},
},
schema: {
data: "Data",
total: "Total"
},
serverPaging: true,
pageSize: 10
});
grid.setDataSource(newdataSource);
grid.dataSource.fetch();

If I understand right, you want to export all data including paged data. This can be achieved using allPages configuration in excel declaration. When you click the Export to Excel button, all data is read from the backend. Large data sets may have significant affect to page performance.
<div id="grid"></div>
<script>
$("#grid").kendoGrid({
toolbar: ["excel"],
excel: {
allPages: true
},
dataSource: {
transport: {
read: {
url: "http://demos.telerik.com/kendo-ui/service/products",
dataType: "jsonp"
}
},
pageSize: 10
},
pageable: true
});
</script>

Related

Kendo Grid not showing data with proper json being returned

My kendo grid is not showing data after successfully calling a web method and seeing data being returned in the ajax request.
$(document).ready(function () {
var filterSource = new kendo.data.DataSource({
transport: {
read: function (options) {
$.ajax({
type: "GET",
url: "DoJo.aspx/GetProjects",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
// msg.d has the json data
}
});
}
},
schema: {
model: {
fields: {
ProjNum: {type: "string"},
Stat: {type: "string"}
}
},
data: "d"
},
change: function (e) {
// e.items is empty
}
});
$("#grid").kendoGrid({
dataSource: filterSource,
columns: [
{
field: "ProjNum", title: "Project Number", width: "130px", filterable: {
multi: true,
dataSource: filterSource
}
},
{
field: "Stat", title: "Status", filterable: {
multi: true,
dataSource: filterSource
}
}
]
});
})
The JSON below is in an array format.
[{"ProjNum":"12345","Stat":null,"ProjTitle":"Test Title","ClientName":"Test Client","ClientContactName":"Test Name","ClientFacilityLocation":"Test Location","SourceOfContact":"Test Contact","ProjManager":"Test Manager","Department":"Test Department"}]
Why is change callback returning an empty e.items? If I remove data: "d" it returns e.Items with the JSON data.
When you set dataSource.transport.read to a function and invoke the ajax call yourself, you need to pass the result (or error) back into the dataSource, like so:
var filterSource = new kendo.data.DataSource({
transport: {
read: function (options) {
$.ajax({
type: "GET",
url: "DoJo.aspx/GetProjects",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
// msg.d has the json data
// notify the data source that the request succeeded
options.success(msg);
},
error: function(msg) {
// notify the data source that the request failed
options.error(msg);
}
});
}
},
schema: {
model: {
fields: {
ProjNum: { type: "string" },
Stat: { type: "string" }
}
},
data: "d"
},
change: function (e) {
// e.items is empty
}
});
See the documentation for more information.

Bind Kendo Grid data with dropdown value

I have kendo dropdownlist on page which is fetching results from database as below. I also have a grid at the same page at same time which needs kendo dropdownlist value i.e the value from years dropdownlist but I am unable to get it at the same time.This is how I am following. Where I am doing wrong.
<script type="text/javascript">
var GridUrl;
$("#Years").kendoDropDownList({
dataTextField: "Name",
dataValueField: "Id",
dataSource: {
transport: {
read: {
dataType: "json",
url: "../../Service/GetYears"
}
}
}
});
$(document).ready(function () {
BindGridData();
GridUrl = '#Url.Action("Read", "Home")';
});
function BindGridData()
{
GridDataSource = new kendo.data.DataSource({
type: "aspnetmvc-ajax",
serverFiltering: true,
serverPaging: true,
serverSorting: true,
pageSize: 10,
transport: {
read: {
url: GridUrl,
data: { year: $('#Years').val() }
}
},
schema: {
data: "Data", total: "Total"
}
});
}
Changing line to this
year: $('#Years').data("kendoDropDownList").value()
should do a trick. You need to get instance of kendoDropDownListwidget in order to get its value. You need to do so, because kendoDropDownListwidget value is not saved directly into html element
First of all, you need to move the initialisation of the kendoDropDownList inside the document ready function. If you don't you may end up refering to elements that are not loaded (yet).
The second change that should be done is how you get the value from the kendoDropDownList. Usually, you should refer to the widget instead of the DOM element: $('#Years').data("kendoDropDownList").value()
Finally, you didn't mention how and when your grid was binded but you may want to refresh the grid data if the user change the dropdown value. If it's the case, you may want to use change event of the dropdown to refresh the grid data.
$(document).ready(function () {
$("#Years").kendoDropDownList({
dataTextField: "Name",
dataValueField: "Id",
dataSource: {
transport: {
read: {
dataType: "json",
url: "../../Service/GetYears"
}
}
},
change: function(e) {
$("#YourGrid").data("kendoGrid").dataSource.read();
}
});
BindGridData();
GridUrl = '#Url.Action("Read", "Home")';
});
function BindGridData() {
GridDataSource = new kendo.data.DataSource({
type: "aspnetmvc-ajax",
serverFiltering: true,
serverPaging: true,
serverSorting: true,
pageSize: 10,
transport: {
read: {
url: GridUrl,
data: { year: $('#Years').data("kendoDropDownList").value() }
}
},
schema: {
data: "Data", total: "Total"
}
});
}

Typeahead not work in dialog edit of jqGrid

I tried to response the json from server like the official demo.
But the dropdown suggesion doesn't show up.
Could anyone tell me what I missed?
I only change the url from the demo code:
{
label: 'Ship Name2',
name: 'ShipName2',
width: 150,
editable: true,
edittype: "text",
editoptions: {
dataInit: function (element) {
$(element).attr("autocomplete","off").typeahead({
appendTo : "body",
source: function(query, proxy) {
$.ajax({
url: 'mysite',
dataType: "jsonp",
data: {term: query},
success : proxy
});
}
});
}
}
}, {
label: 'Ship Name',
name: 'ShipName',
width: 150,
editable: true,
edittype: "text",
editoptions: {
dataInit: function (element) {
$(element).attr("autocomplete","off").typeahead({
appendTo : "body",
source: function(query, proxy) {
$.ajax({
url: 'http://trirand.com/blog/phpjqgrid/examples/jsonp/autocompletepbs.php?callback=?&acelem=ShipName',
dataType: "jsonp",
data: {term: query},
success : proxy
});
}
});
}
}
}
P.S. My servlet return the same json which is exact the same as demo's.
Thanks!!
Edit 1: Is it possible that if I want to use typeahead in this demo, the response should not just be a json?
If I execute the url in the demo, I would get the following javascript instead of json:
<script type='text/javascript'>
jQuery(document).ready(function() {
if(jQuery.ui) {
if(jQuery.ui.autocomplete){
jQuery('ShipName').autocomplete({
"appendTo":"body",
"disabled":false,
"delay":300,
"minLength":1,
"source":function (request, response){
request.acelem = 'ShipName';
request.oper = 'autocmpl';
$.ajax({
url: "autocompletep.php",
dataType: "json",
data: request,
type: "GET",
error: function(res, status) {
alert(res.status+" : "+res.statusText+". Status: "+status);
},
success: function( data ) {
response( data );
}
});
}});
jQuery('ShipName').autocomplete('widget').css('font-size','11px');
jQuery('ShipName').autocomplete('widget').css('z-index','1000');
}
}
});
</script>
Could anyone tell me why?
The demo uses JSONP to obtain the data. If you are in local site you will need to remove calcback=? parameter.
The very basic testis is not to use ajax in typeahead, but array as data source. This way you will be sure that this work correct

Why is Kendo dropDownList undefined

I want to populate a Kendo dropdownlist with data from a database.
That's what I call the "frwMantenimientoEmpresas.aspx / SelectProvincias" method.
My problem is that the value "undefined" after making the call, in the dropdownlist appears ...
dataSource1 = new kendo.data.DataSource({
serverFiltering: true,
transport: {
read: {
beforeSend: function (req) {
//alert("");
},
async: false,
url: "frwMantenimientoEmpresas.aspx/SelectProvincias",
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8"
}
},
schema: {
model: {
fields: {
UIDProvincia: { type: "int" },
Nombre: { type: "string" }
}
}
}
});
$("#dropProv").kendoDropDownList({
dataSource:dataSource1,
dataTextField: "Nombre",
dataValueField: "UIDProvincia",
autoBind: true,
});
The read method calls the server SelectProvincias method correctly..
At this point dropDownList = undefined??

Kendo Grid groupping

I read this topic and use open source edition of kendo web, my current version is Kendo UI Web v2012.3.1114. My problem is exist as the link above and I could not solve it.
Part of my script is here:
function load() {
var grid = $("#grid").data("kendoGrid");
if (grid) {
//destroy the previous Grid instance
grid.destroy();
//clean up the html
grid.wrapper.html("");
}
var crudServiceBaseUrl = "WebForm.aspx",
//datasource = null;
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl + "?q=load&sql=" + $("#tbSQL").val(),
dataType: "jsonp"
},
update: {
url: crudServiceBaseUrl + "?q=update&sql=" + $("#tbSQL").val(),
dataType: "jsonp"
},
destroy: {
url: crudServiceBaseUrl + "?q=destroy&sql=" + $("#tbSQL").val(),
dataType: "jsonp"
},
create: {
url: crudServiceBaseUrl + "?q=create&sql=" + $("#tbSQL").val(),
dataType: "jsonp"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
batch: true,
pageSize: 20,
schema: getmodel()
$("#grid").kendoGrid({
dataSource: dataSource,
navigatable: true,
//pageable: true,
selectable: true,
//groupable: true,
sortable: true,
pageable: {
refresh: true,
pageSizes: true
},
height: 500,
toolbar: ["create", "save", "cancel"],
columns: getColumns(),
editable: true
});
}
Every thing is ok, but only after loading page I can only One time group by headers.
It seems that this behavior is improved in the latest version of KendoUI 2012 Q3 SP1 (v.2012.3.1315), where the grouping is working as expected. For convenience I created this sample.

Resources