MCPcopy Index your code
hub / github.com/TanStack/table / updateOffset

Function updateOffset

packages/table-core/src/features/ColumnSizing.ts:375–416  ·  view source on GitHub ↗
(
          eventType: 'move' | 'end',
          clientXPos?: number,
        )

Source from the content-addressed store, hash-verified

373 const newColumnSizing: ColumnSizingState = {}
374
375 const updateOffset = (
376 eventType: 'move' | 'end',
377 clientXPos?: number,
378 ) => {
379 if (typeof clientXPos !== 'number') {
380 return
381 }
382
383 table.setColumnSizingInfo((old) => {
384 const deltaDirection =
385 table.options.columnResizeDirection === 'rtl' ? -1 : 1
386 const deltaOffset =
387 (clientXPos - (old?.startOffset ?? 0)) * deltaDirection
388 const deltaPercentage = Math.max(
389 deltaOffset / (old?.startSize ?? 0),
390 -0.999999,
391 )
392
393 old.columnSizingStart.forEach(([columnId, headerSize]) => {
394 newColumnSizing[columnId] =
395 Math.round(
396 Math.max(headerSize + headerSize * deltaPercentage, 0) * 100,
397 ) / 100
398 })
399
400 return {
401 ...old,
402 deltaOffset,
403 deltaPercentage,
404 }
405 })
406
407 if (
408 table.options.columnResizeMode === 'onChange' ||
409 eventType === 'end'
410 ) {
411 table.setColumnSizing((old) => ({
412 ...old,
413 ...newColumnSizing,
414 }))
415 }
416 }
417
418 const onMove = (clientXPos?: number) => updateOffset('move', clientXPos)
419

Callers 2

onMoveFunction · 0.85
onEndFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected