Telerik Forums
Kendo UI for jQuery Forum
16 answers
1.4K+ views
I have been playing around with the WebAPI and have got the paging working. This is a workaround until the day comes when WebAPI and Kendo can work together properly.

The principle is to create a method that has the parameters take, skip, page and pageSize.

Example, in my "Transactions" Controller I have a WebAPI method:
    Public Function GetTransactions(take As Integer, skip As Integer, page As Integer, pageSize As Integer
As
 IQueryable(Of Transaction)        
Return
 repository.GetPaged(take, skip, page, pageSize)     End Function
This will then take the parameters passed by the URL generated from the kendo data source.

Example (from fiddler)
      /[your web api path]/api/Transactions?take=10&skip=0&page=1&pageSize=10

Before this will work, it is important for paging that the kendo data source knows the total number of rows that the query could return if it were not constrained by the take parameter. Not knowing how to add this to the results as a separate field, I added this to each row returned (added a property to the Transaction class). A bit of a waste, but it works.

It required a small function in the schema section of the data source that returns total value from the first row of the data set.

So, to the Kendo code. This uses a shared data source and a grid + chart. Of course, you'll need to change the data/uri to suit your WebAPI data.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--In the header of your page, paste the following for Kendo UI Web styles-->
    <link href="scripts/kendo/styles/kendo.common.min.css" rel="stylesheet" type="text/css" />
    <link href="scripts/kendo/styles/kendo.default.min.css" rel="stylesheet" type="text/css" />
 
    <!--Then paste the following for Kendo UI Web scripts-->
    <script src="scripts/kendo/js/jquery.min.js"></script>
    <script src="scripts/kendo/js/kendo.all.min.js"></script>
    <title></title>
</head>
<body>
    <div id="example" class="k-content">
            <div id="grid"></div>
            <div id="chart"></div>
 
            <script type="text/javascript">
                var sharedData;
 
                function createChart() {
                    $("#chart").kendoChart({
                        dataSource: sharedData,
                        autoBind: false,
                        legend: {
                            visible: false
                        },
                        series: [{
                            type: "column",
                            field: "Amount"
                        }],
                        axisDefaults: {
                            labels: {
                                font: "11px Tahoma, sans-serif"
                            }
                        },
                        valueAxis: {
                            labels: {
                                format: "{0:N0}"
                            }
                        },
                        categoryAxis: {
                            field: "TransactionCreated"
                        },
                        tooltip: {
                            visible: true,
                            format: "{0:N0}"
                        }
                    });
                }
 
                function createGrid() {
                    $("#grid").kendoGrid({
                        dataSource: sharedData,
                        autoBind: false,
                        height: 250,
                        filterable: true,
                        sortable: true,
                        pageable: true,
                        columns: [{
                            field: "Id",
                            filterable: false
                        },
                        {
                            field: "TransactionCreated",
                            title: "Date Processed",
                            width: 100,
                            format: "{0:MM/dd/yyyy HH:MM}",
                            filterable: false
                        },
                        {
                            field: "TransactionCompleted",
                            title: "Date Complete",
                            width: 100,
                            format: "{0:MM/dd/yyyy HH:MM}",
                            filterable: false
                        },
                        {
                            field: "CardType",
                            title: "Card Type"
                        },
                        {
                            field: "Settled",
                            title: "Settled"
                        },
                        {
                            field: "Amount",
                            title: "Amount",
                            filterable: false
                        },
                        {
                            field: "Currency",
                            title: "Currency"
                        },
                        {
                            field: "OrderReference",
                            title: "Order Reference",
                            filterable: false
                        },
                        {
                            field: "MaskedCardNumber",
                            title: "Card Number",
                            filterable: false
                        },
                        {
                            field: "ReferenceNumber",
                            title: "Reference Number",
                            filterable: false
                        },
                        {
                            field: "ResponseCode",
                            title: "Response Code"
                        }
                    ]
                    });
                }
 
                $(document).ready(function () {
                    sharedData = new kendo.data.DataSource({
                        transport: {
                            read: "http://localhost/WebAPITest/api/Transactions",
                            datatype: "json"
                        },
                        schema: {
                            total: function (result) {
                                var cnt = 0;
                                if (result.length > 0)
                                    cnt = result[0].Count;
                                return cnt;
                            },
                            model: {
                                fields: {
                                    Id: { type: "number" },
                                    TransactionCreated: { type: "date" },
                                    TransactionCompleted: { type: "date" },
                                    CardType: { type: "string" },
                                    Settled: { type: "string" },
                                    Amount: { type: "number" },
                                    Currency: { type: "string" },
                                    OrderReference: { type: "string" },
                                    MaskedCardNumber: { type: "string" },
                                    ReferenceNumber: { type: "number" },
                                    ResponseCode: { type: "string" },
                                    Count: { type: "number" }
                                }
                            }
                        },
                        page: 1,
                        pageSize: 10,
                        serverPaging: true,
                        serverFiltering: true,
                        serverSorting: true
                    });
 
                    createGrid();
                    createChart();
 
                    sharedData.fetch();
 
 
                });
            </script>
    </div>
</body>
</html>

Hope this helps.
Mike
Top achievements
Rank 1
 answered on 20 Jun 2012
3 answers
291 views
Hi. I am new with KendoUI and developing a mobile test app. I connect to a website whene i have a PHP page and gets the categories data from Nothwind database. I got an json as thi s:
{"Result":"OK",
"Rows":[
{"CategoryID":1,"CategoryName":"Beverages","NumProducts":12},
{"CategoryID":2,"CategoryName":"Condiments","NumProducts":12},
....
]
}

And html code is :
        <script type="text/javascript">
        document.addEventListener("deviceready", onDeviceReady, false);


        function onDeviceReady() {
          $.mobile.allowCrossDomainPages = true;
          refreshCategoryList();
       }
       
 // ----------------------------------------------------------
     // Fill Categories List 
     // ----------------------------------------------------------
  function refreshCategoryList() {
var url = 'http://MyServer';
$.getJSON(url, function(res) {
  var result = res.Result;
  if (result == 'OK') {
    var categoryArray = res.Rows;
    $("#categoryList").kendoMobileListView({
    template : '<li><a href="#proPage" oncclik="sessionStorage.cat=${Rows.CategoryID}">${Rows.categoryName}' +
      '<span class="ui-li-count">${Rows..NumProducts}</span></a></li>',
           dataSource: kendo.data.DataSource.create( categoryaArray)
       });     
  }
});
 }
 
        </script> 
        
    </head>
    <body>
    <ul id="categoryList"></ul>
    
<script>
        window.kendoMobileApplication = new kendo.mobile.Application(document.body);
    </script>  

But i got this message in teh web console :

E/Web Console(693): TypeError: Result of expression 'd' [undefined] is not an object. at file:///android_asset/www/js/kendo.mobile.min.js:8

Any hint, please...
Yamil
Top achievements
Rank 1
 answered on 20 Jun 2012
0 answers
154 views
I have a grid that allows a user to display data in both grouped and none grouped format. The datasource (ds) is using json to read the data from the server. The datasource is currently configured to do server side paging and filtering. I would like to also enable this datasource to be able to do server side grouping and Aggregates on the data.

My ds currently defines the schema: { data: "DateList", total: "TotalResults” model: { //fields are declared}}

And my grid currently defines the columns that need to be displayed.

In what format does my code need to returned the grouped data to the ds? And also how do I need to format the Aggregates that are calculated for each grouping?  Keeping in mind that the grid allows for displaying of non grouped and grouped data.  Do I need to change anything with how the ds is defined in regards to the schema? Do I need to change anything with how the grid is defined in regards to the column list?

An example of a grid that allows for grouped and none grouped results and does server side grouping would help.
MK
Top achievements
Rank 1
 asked on 20 Jun 2012
0 answers
101 views
I am trying to get the kendo grid to work for a project I'm working on. It seems as though most of it is working except I can't seem to pass any changing value into the data. I have provided an example jsFiddle: http://jsfiddle.net/9tkg8/2/
I would like the value in the grid to update and reflect the value that is currently stored in the js variable. As you can tell from the example the js variable is being updated(try sorting the columns a couple of times), but the value in the grid isn't. How can I get this to work?
Zack
Top achievements
Rank 1
 asked on 20 Jun 2012
4 answers
338 views
Hello,

Just to be clear on the commercial license agreement, I'm prohibited from changing any part of the source code? Even for internal use where it would not be distributed, it does still violate the agreement? So for example, if I don't like the pager on the Kendo Grid and I want to have a First and Last buttons, my only real option to be in agreement with the license is to contact Telerik, and ask them to support a feature (if they even accept it), and wait for the release?
ryan
Top achievements
Rank 1
 answered on 20 Jun 2012
1 answer
53 views
The documentation for chart configuration is very hard to parse through and find what you are looking for.

http://www.kendoui.com/documentation/dataviz/chart/configuration.aspx

There is no way to go through and find what you are looking for without using CTRL+F in the browser. Can you please consider updating to be more user friendly and allow to find what you are looking for faster?
Brandon
Telerik team
 answered on 20 Jun 2012
1 answer
116 views
Hi

Are there any plans for a 'Spider Chart', I think that it would be a great addition to your offerings...

Regards

Daryl
Iliana Dyankova
Telerik team
 answered on 20 Jun 2012
0 answers
91 views
Have a look (attached)

So in the example, this is template 1
<script id="campus-template" type="text/x-kendo-template">
    <div class="campus-phase-block" data-bind="attr: {data-campusid: CampusID}">
        <h3 data-bind="text: Campus"></h3>
        <ul data-template="phase-template" data-bind="source: PhaseData" class="phaseBlocks">
             
        </ul>
        <div class="verbs">
            <h3>Available Actions</h3>
            <ul data-template="verb-template" data-bind="source: getVerbs" class="dynamic-list">
 
            </ul>
        </div>
         
    </div>
</script>

..and here's template 2:
<script id="verb-template" type="text/x-kendo-template">
        <li data-bind="click: onRunVerb">
            <span data-bind="text: text"></span>
        </li>
    </script>


So the populating of template 1 works fine, 3 items bound, 3 items displayed.  So template 2 however is supposed to return a list of verbs (getVerbs) based on the current ID of that item.

getVerbs: function (campus) {
//Figure out what phase the campus is in, and apply the right verbs
var dynamicItemVerbs = this.verbs[campus.Phase - 1].verbs
var commonVerbs = this.verbs[7].verbs; //The default items
/*
for (var i = 0; i < itemVerbs.length; i++) {
returnVerbs.push(itemVerbs[i]);
}
*/
var merge = $.merge(commonVerbs, dynamicItemVerbs);
return merge;
},

So debugging, it seems like $merge is appending the dynamic items to commonVerbs.  Does not making a varable off the "this.verbs[7].verbs" make a copy of that array?

What's the preferred way to do this instead?...serialize to JSON and back or something?
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
 asked on 20 Jun 2012
0 answers
79 views
When I have a groupable table, and I group by one of the headers, the left-most header gets really small (in width). See attached screenshot
Nick
Top achievements
Rank 1
 asked on 20 Jun 2012
2 answers
328 views
Hi Kendo Team,

Scenario:
I would like to draw two area charts in a single chart such that one of them is drawn above the category axis and the other one below the category axis, with only positive numbers being displayed along the value axis.

Partial solution:
I drew one chart with positive values and the other with negative values and it is working as expected i.e. showing negative labels for the chart drawn with negative values. I would like to format the values axis to display positive numbers (for the numbers in negative direction). Is this possible?

Ideally, I would like to be able to draw the second chart with positive values but in reverse direction (this will help display positive labels for the second chart). I know there is an option to reverse the value axis but not sure how can I use it to draw two charts - one in normal direction and other in reverse.

Thanks,
Amrinder
Amrinder
Top achievements
Rank 1
 answered on 20 Jun 2012
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?