Created
September 14, 2016 21:09
-
-
Save nelreina/0af03947be904e57ff7a6ee2a9f4b487 to your computer and use it in GitHub Desktop.
Get Grid Row Columns/ React Utility function to for splitting data in row components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment