Sticky Rows

1 Answer 135 Views
Grid
Trevor
Top achievements
Rank 1
Trevor asked on 10 May 2022, 03:42 PM
Is it possible to make rows sticky similar to the locked option we have for columns?

1 Answer, 1 is accepted

Sort by
0
Accepted
Petar
Telerik team
answered on 13 May 2022, 02:04 PM

Hi Trevor,

Here is a StackBlitz example demonstrating how you can achieve the desired functionality.  To achieve the sticky rows functionality we have to use the cellRender property of the Grid and pass a custom template to it. In the provided example the template we use is the following one:

<template v-slot:cellRenderTemplate="{ props }">
  <td
    v-if="props.dataItem.locked || props.field === 'locked'"
    :style="[
      {
        top: getTop(props.dataItem) + 'px',
        bottom: getBottom(props.dataItem) + 'px',
        'text-align': centerText(props.field),
      },
    ]"
    :class="classNames(props.dataItem, props.className)"
    @click="handleLockRowChange(props.dataItem) && props.field === 'locked'"
  >
    <span
      v-if="props.dataItem.locked && props.field === 'locked'"
      class="k-icon k-i-pin"
    ></span>
    <span
      v-else-if="!props.dataItem.locked && props.field === 'locked'"
      class="k-icon k-i-unpin"
    ></span>
    <span v-else> {{ getNestedValue(props.field, props.dataItem) }} </span>
  </td>
  <td v-else>
    {{ getNestedValue(props.field, props.dataItem) }}
  </td>
</template>

Please check the above link and let me know if you have questions about the suggested implementation.

Regards,
Petar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Trevor
Top achievements
Rank 1
commented on 17 May 2022, 12:49 PM

Thank you for this! I was already using templates for formatting cell backgrounds so I added the class in there and the top/bottom indicators and it worked perfect!
Petar
Telerik team
commented on 17 May 2022, 01:02 PM

Hi, Trevor.

I am happy to hear that the suggested implementation has helped you achieve what you need in your application :).

Tags
Grid
Asked by
Trevor
Top achievements
Rank 1
Answers by
Petar
Telerik team
Share this question
or