Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I show the horizontal scrollbar on a kendo ui grid after filtering?

I have a kendo UI grid with many columns. Columns that overflow can be viewed by scrolling horizontally. However, if you

1) scroll to a column that is not initially displayed and

2) filter on that column such that no rows match the filter criteria

the grid will no longer allow scrolling horizontally. The column that had the filter applied cannot be cleared.

How can I show the horizontal scrollbar after such filtering?

Here's a jsfiddle where you can see the issue

http://jsfiddle.net/9sxkG/1/

Here's the code:

var dataItem = {};
var columns = [];

for (var i = 0; i < 20; i++) {
    dataItem['col' + i] = i;
    columns.push( {
        field: 'col' + i,
        width: 80,
        filterable: true,
        type: 'number'
    } );
}

$("#grid").kendoGrid({
    scrollable:true,
    columns: columns,
    filterable: true,
    dataSource: [dataItem]
});

For example, go to column 18 and filter on equal to 20 to see the issue.

like image 914
James Avatar asked Feb 12 '13 02:02

James


People also ask

How do I turn on horizontal scrollbar in kendo grid?

Apply Scrollable() and give Width for each columns and then if the total width exceeds the width of the grid the horizontal scrollbar will appear.

How do I add a horizontal scrollbar?

Basic Horizontal Scroll Box To make a scroll box with a horizontal scroll, you need to use the overflow-x property. Specifically, you need to use this code: overflow-x:scroll; . This tells your browser to create scroll bars on the x (horizontal) axis, whenever the contents of the container is too wide.

How do I add a scrollbar to my Kendo grid?

scrollable Boolean|Object (default: true) If set to true the grid will display a scrollbar when the total row height (or width) exceeds the grid height (or width). By default scrolling is enabled.

How do you handle horizontal scrollbar?

To enable horizontal scrolling, we can use the CSS property overflow-x. If we assign the value scroll to the overflow-x property of the container element, the browser will hide horizontally overflowing content and make it accessible via horizontal scrolling.


1 Answers

I had the same problem, I solved it adding a empty row to the grid.
Code:

var dataItem = {};
var columns = [];

for (var i = 0; i < 20; i++) {
  dataItem['col' + i] = i;
  columns.push( {
    field: 'col' + i,
    width: 80,
      filterable: true,
      type: 'number'
  } );
}

$("#grid").kendoGrid({
    scrollable:true,
    columns: columns,
    filterable: true,
    dataSource: [dataItem],
    dataBound: function(e) {  
        if(this.dataSource.view().length == 0) {
             var colspan = this.content.find("table col").length;
             this.content.find("table").append("<tr><td colspan=" + colspan + "></td></tr>");
        }
        $("#grid").find(".k-grid-footer-wrap").scrollLeft($("#grid").find(".k-grid-content").scrollLeft());        
        this.content.bind('scroll', function () {
            $("#grid").find(".k-grid-footer-wrap").scrollLeft(this.scrollLeft);
        });
    }
})
like image 81
Gonzalo Avatar answered Sep 20 '22 00:09

Gonzalo