Search code examples
javascriptkendo-uikendo-gridkendo-template

How I can add anchor and button in same column of kendo grid?


I have a kendo grid where i want to add a link and a button in same column of kendo grid. When i add button into a grid column, my link from the template disappears from the column.

My grid configuration:

subCategoryGrid: {
    sortable: true,
    height: 600,
    pageable: {
        previousNext: false,
        pageSizes: false
    },
    toolbar: [{
        template: kendo.template('<kendo-tabstrip><ul class="header-backGround"><li ng-class="{\'k-state-hover k-state-active\': defaultAllTab}"><a class="k-grid-add border"  ng-click="getAllSubCategories()">All</a></li>')
    }, {   
        template: kendo.template('<li ng-class="{\'k-state-hover k-state-active\': defaultPendingTab}"><a class="k-grid-add border" ng-click="getPendingSubCategories()">Pending Review</a></li>')
    }, {
        template: kendo.template('<li ng-class="{\'k-state-hover k-state-active\': defaultReviewTab}"><a class="k-grid-add border" ng-click="getReviewedSubCategories()">Reviewed</a></li></ul><kendo-tabstrip>')
    }],
    filterable: true,
    columns: [{
        template: '<strong><span ng-if="this.dataItem.sortCode === 1" class="text-success">NEW</span><span ng-if="this.dataItem.sortCode === 2" class="text-danger">!</span></strong>',
        width: '30px'
    }, {  
        template: kendo.template('<a ngMouseup="font-linksColor ng-class="\'k-state-hover k-state-active\'"" ng-click=\'fetchSubCategoryDetails(this.dataItem)\'>{{this.dataItem.subCategoryName}}</a>'),
        field: 'subCategoryName',
        title: 'Subcategory',
        width: '100px',
        command: [
              {
                  text: 'Details',
                  template: '<button class=\'k-button k-button-icontext\' ng-click=\'showDetail(this.dataItem)\'>Detail</button>',
                  title: 'Action',
                  width: '25px'
              },
          ],

    }, {
        field: 'status',
        title: 'Status',
        width: '65px'
    }]
},

Solution

  • You can't use the template and command option for a column at the same time; if you use the template, you need to create your button there, i.e.:

    template: kendo.template('<a> ...</a><button>...</button>'),