nelreina
9/14/2016 - 9:09 PM

Get Grid Row Columns/ React Utility function to for splitting data in row components

Get Grid Row Columns/ React Utility function to for splitting data in row components

import React from 'react';

export const getGridRowColumns = (data, columns, Component, props ) => {
  let retRows = [];
  const rowCount = Math.ceil(data.length/ columns);
  for (let i = 0; i < rowCount; i++) {
    let rowData = [];
    for (let x = 0; x < columns; x++) {
      rowData.push( data[x + (i * columns)])
    }
    retRows.push(<Component key={i}  data={rowData} {...props} />)
  }

  return retRows;
}