|
| 1 | +--- |
| 2 | +title: Enabling Horizontal Mousepad Scrolling with FrozenColumnCount in UI for ASP.NET AJAX Grid |
| 3 | +description: Learn how to enable horizontal scrolling using a laptop trackpad or gestures when FrozenColumnCount is set in the UI for ASP.NET AJAX Grid. |
| 4 | +type: how-to |
| 5 | +page_title: Mousepad Scrolling with Frozen Columns |
| 6 | +meta_title: Mousepad Scrolling with Frozen Columns |
| 7 | +slug: grid-scrolling-with-frozen-columns-with-mousepad |
| 8 | +tags: grid, asp.net ajax, frozen columns, scrolling, javascript workaround, mousepad |
| 9 | +res_type: kb |
| 10 | +ticketid: 1696661 |
| 11 | +--- |
| 12 | + |
| 13 | +## Environment |
| 14 | + |
| 15 | +<table> |
| 16 | +<tbody> |
| 17 | +<tr> |
| 18 | +<td>Product</td> |
| 19 | +<td>Grid for UI for ASP.NET AJAX</td> |
| 20 | +</tr> |
| 21 | +<tr> |
| 22 | +<td>Version</td> |
| 23 | +<td>All</td> |
| 24 | +</tr> |
| 25 | +</tbody> |
| 26 | +</table> |
| 27 | + |
| 28 | +## Description |
| 29 | + |
| 30 | +When using the Grid with the `FrozenColumnCount` property set, native horizontal scrolling with a laptop trackpad or gestures becomes unavailable. This limitation arises because the Grid applies `overflow: hidden` to its scrollable container and uses a "fake" scrollbar to manage frozen columns. Users are typically restricted to using the grid's built-in scrollbars for scrolling. |
| 31 | + |
| 32 | +There is no official solution to enable native horizontal scrolling in this scenario. However, a custom JavaScript workaround can allow trackpad or gesture-based scrolling by intercepting wheel or touch events and manually adjusting the scroll position. |
| 33 | + |
| 34 | +This knowledge base article also answers the following questions: |
| 35 | + |
| 36 | +- How to scroll horizontally in ASP.NET AJAX Grid with FrozenColumnCount enabled? |
| 37 | +- Is there a workaround for trackpad scrolling in ASP.NET AJAX Grid frozen columns? |
| 38 | +- How to enable gesture-based scrolling for frozen columns in ASP.NET AJAX Grid? |
| 39 | + |
| 40 | +## Solution |
| 41 | + |
| 42 | +To enable scrolling using a laptop trackpad or gestures, use the following JavaScript workaround to adjust the scroll position of the container based on the `deltaX` value from the event. |
| 43 | + |
| 44 | +````ASP.NET |
| 45 | +<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"> |
| 46 | + <MasterTableView AutoGenerateColumns="False" DataKeyNames="OrderID"> |
| 47 | + <Columns> |
| 48 | + ... |
| 49 | + </Columns> |
| 50 | + </MasterTableView> |
| 51 | + <ClientSettings> |
| 52 | + <ClientEvents OnGridCreated="onGridCreated" /> |
| 53 | + <Scrolling AllowScroll="True" UseStaticHeaders="True" FrozenColumnsCount="1" /> |
| 54 | + </ClientSettings> |
| 55 | +</telerik:RadGrid> |
| 56 | +```` |
| 57 | + |
| 58 | +````JavaScript |
| 59 | +function onGridCreated(sender, args) { |
| 60 | + let gridScrollableDiv = sender.get_element().querySelector(".rgDataDiv"); // Find the scrollable container of the grid. |
| 61 | + |
| 62 | + gridScrollableDiv.addEventListener('wheel', function (e) { // Add a wheel event listener to enable trackpad scrolling. |
| 63 | + if (e.deltaX !== 0) { |
| 64 | + gridScrollableDiv.scrollLeft += e.deltaX; // Adjust scroll position. |
| 65 | + e.preventDefault(); // Prevent default behavior. |
| 66 | + } |
| 67 | + }, { passive: false }); |
| 68 | +} |
| 69 | +```` |
| 70 | + |
| 71 | +Limitations: |
| 72 | + |
| 73 | +- This workaround does not update the position of the horizontal scrollbar visually. |
| 74 | +- It is not officially supported by Telerik and may require adjustments depending on your implementation. |
| 75 | + |
| 76 | +## See Also |
| 77 | + |
| 78 | +- [RadGrid](https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/overview) |
| 79 | +- [Wheel Event Documentation - MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/wheel_event) |
0 commit comments