最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Kendo Grid and ui-sref rounding up number - Stack Overflow

programmeradmin0浏览0评论

I'm trying to do something relatively simple, but having an issue that is driving me mad, I'm sure I am missing something simple.

I have an AngularJS site that's for the most part working fine, and in that I have a Kendo Grid. All I am trying to do is have the first column of the grid have a link to another page, using an ID that is in the grid data.

The code I am using is below, and this works in that it creates a link mostly based on what I am asking but for some weird reason the ID it uses as part of the URL is being rounded up. To give you an example the actual ID I need to use is 37509488620601829, this is what is returned by my API and what is shown if I make the ID field a column in my table, but in the link this gets rounded up to 37509488620601830 (note the last 2 digits).

Any insight on this is appreciated.

   <div kendo-grid k-data-source="SearchResultsGrid" k-columns="[{'field': 'Name' , 'title':'Name', 'template': '<a ui-sref=&quot;Id({ Id: #: Id # }) &quot;>#: Name #</a>'  },{'field': 'Alias' , 'title':'Alias' },{'field': 'Server' , 'title':'Server' },{'field': 'Faction' , 'title':'Faction' }]"></div>

I'm trying to do something relatively simple, but having an issue that is driving me mad, I'm sure I am missing something simple.

I have an AngularJS site that's for the most part working fine, and in that I have a Kendo Grid. All I am trying to do is have the first column of the grid have a link to another page, using an ID that is in the grid data.

The code I am using is below, and this works in that it creates a link mostly based on what I am asking but for some weird reason the ID it uses as part of the URL is being rounded up. To give you an example the actual ID I need to use is 37509488620601829, this is what is returned by my API and what is shown if I make the ID field a column in my table, but in the link this gets rounded up to 37509488620601830 (note the last 2 digits).

Any insight on this is appreciated.

   <div kendo-grid k-data-source="SearchResultsGrid" k-columns="[{'field': 'Name' , 'title':'Name', 'template': '<a ui-sref=&quot;Id({ Id: #: Id # }) &quot;>#: Name #</a>'  },{'field': 'Alias' , 'title':'Alias' },{'field': 'Server' , 'title':'Server' },{'field': 'Faction' , 'title':'Faction' }]"></div>
Share Improve this question edited Jul 4, 2015 at 13:30 Pankaj Parkar 136k23 gold badges240 silver badges303 bronze badges asked Apr 26, 2015 at 11:36 Sam CoganSam Cogan 4,3347 gold badges49 silver badges77 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4 +100

First, keep configuration like this out of the HTML. This makes things much easier to read and manage. Second, the remended way for binding is to use angular's ng-bind or interpolation ({{}}) methods rather than Kendo's default template binding. Within the template that you supply to the grid, you have access to a dataItem variable. This is a reference to the row item.

HTML:

<div kendo-grid k-options="gridOptions"></div>

Controller:

scope.gridOptions = {
    dataSource: SearchResultsGrid,
    columns: [{
        'field': 'Name',
        'title': 'Name',
        // 'template': '<a ui-sref=&quot;Id({ Id: #: Id # }) &quot;>#: Name #</a>'
        'template': '<a ui-sref="{{dataItem.Id}}">{{dataItem.Name}}</a>'
    }, {
        'field': 'Alias',
        'title': 'Alias'
    }, {
        'field': 'Server',
        'title': 'Server'
    }, {
        'field': 'Faction',
        'title': 'Faction'
    }]
};

Try changing this part of your code

'<a ui-sref=&quot;Id({ Id: #: Id # }) &quot;>'

To

'<a ui-sref="Id({ #: Id # })">'

You shouldn't have mention that column def from html it self do store it in some scope variable and then assign that scope variable reference to it

Kendo variable is accessible in template using #= variableName # you were doing #: variableName # which is taking you into a problem

Markup

<div kendo-grid k-data-source="SearchResultsGrid" k-columns="columnDef"></div>

Code

$scope.columnDef =[{
    'field': 'Name',
    'title': 'Name',
    'template': '<a ui-sref="Id({ \'Id\': #= Id # })">#= Name #</a>'
}, {
    'field': 'Alias',
    'title': 'Alias'
}, {
    'field': 'Server',
    'title': 'Server'
}, {
    'field': 'Faction',
    'title': 'Faction'
}];
发布评论

评论列表(0)

  1. 暂无评论