Kendo Grid rowTemplate функция нажатия кнопки k не определена - PullRequest
0 голосов
/ 14 сентября 2018

Я использую K-кнопку в Kendo Grid.Для окраски каждой строки я должен был использовать параметры rowTemplate и altRowTemplate.единственная проблема состоит в том, что функция щелчка не связывается должным образом с кнопками.

Я получаю следующую ошибку,

(индекс): 1 Uncaught ReferenceError: viewProfile не определен вHTMLButtonElement.onclick ((index): 1)

Код здесь,

  myGridOptions({
    columns: [
      { field: 'name', title: 'Name', width: '160px'},
      { field: 'address', title: 'address'},
      { field: 'occupation', title: 'Occupation' },          
      { field: 'location', title: 'Location'},
      { field: 'salary', title: 'Salary' },
      { field: 'company', title: 'Company'},
      { field: 'phone', title: 'Phone'},
      //{ field: 'button', title: ' ' }
      { command: { text: 'View Profile', click: viewProfile }, title: ' ', width: '160px' }          
    ],
    dataSource: OccData,
    rowTemplate: '<tr style="background-color: rgb(246,246,246)" data-uid="#= uid #">'+
      '<td>#: name # </td>' +          
      '<td>#: address #</td>' +
      '<td>#: occupation #</td>' +
      '<td>#: location #</td>' +          
      '<td>#: salary #</td>' +
      '<td>#: company #</td>' +          
      '<td> #: phone#</td>' +
      '<td>#: education #</td>' +          
      '<td><button class="k-button" onclick="viewProfile();">View Profile</button></td>'+         
      '</tr>',
      altRowTemplate: '<tr style="background-color: rgb(255,255,255)" data-uid="#= uid #">'+
      '<td>#: name # </td>' +          
      '<td>#: address #</td>' +
      '<td>#: occupation #</td>' +
      '<td>#: location #</td>' +          
      '<td>#: salary #</td>' +
      '<td>#: company #</td>' +          
      '<td> #: phone#</td>' +
      '<td>#: education #</td>' +          
      '<td><button class="k-button" onclick="viewProfile();">View Profile</button></td>'+         
      '</tr>',        
    overflow: false
  });

Я ссылался на несколько ссылок, но не смог найти решение использовать функцию щелчка в rowTemplate.

Любое предложение от разработчиков Kendo !!будет полезно для меня.

Ответы [ 2 ]

0 голосов
/ 14 сентября 2018

Только что получил !!

    <div id="grid"></div>
<script>
$("#grid").kendoGrid({
  columns: [
    { field: "name" },
    { field: "age" },
    {template: "<button class=\"show\">Show</button>"}
  ],
  dataSource: [
    { name: "Jane Doe", age: 30 },
    { name: "John Doe", age: 33 }
  ],
  dataBound: function(e) {
    //console.log("dataBound");
    this.element.find(".show").bind("click", function() {
    alert("Clicked");
  });
  }
});
</script>

Спасибо, https://docs.telerik.com/kendo-ui/api/javascript/ui/grid/events/databound

Это может кому-то помочь !!

0 голосов
/ 14 сентября 2018

В своем определении столбцов вы указываете событие клика viewProfile.У вас есть функция JavaScript с именем viewProfile?

...