PcoWSkbVqDnWTu_dm2ix
Collapse Sidebar

MajorAxis

UITableLayout

TableMajorAxis

MajorAxis determines whether sibling UI elements are treated as rows or columns. Below, the left uses a Enum/TableMajorAxis of RowMajor, and the right uses ColumnMajor.

Row majorColumn major

Note: it seems that this property isn’t making noticeable changes, and rather its behavior is determined by UIGridStyleLayout/FillDirection instead.


Code Samples


Build UI Table

This code sample builds a table of 4 rows, the first having headers. It does this using some for-loops and a UITableLayout. The widths of each column are set using UISizeConstraints.

local frame = script.Parent

-- Table data
local headerWidth = {200, 80, 80}
local headers = {
	"Name",     "Job",    "Cash"}
local data = {
	{"Bob",     "Waiter",   100},
	{"Lisa",    "Police",   200},
	{"George",  "-",         50},
}

-- First, build the table layout
local uiTableLayout = Instance.new("UITableLayout")
uiTableLayout.FillDirection = Enum.FillDirection.Vertical
uiTableLayout.HorizontalAlignment = Enum.HorizontalAlignment.Center
uiTableLayout.VerticalAlignment = Enum.VerticalAlignment.Center
uiTableLayout.FillEmptySpaceColumns = false
uiTableLayout.FillEmptySpaceRows = false
uiTableLayout.Padding = UDim2.new(0, 5, 0, 5)
uiTableLayout.SortOrder = Enum.SortOrder.LayoutOrder
frame.Size = UDim2.new(0, 0, 0, 40) -- The Size of the parent frame is the cell size
uiTableLayout.Parent = frame

-- Next, create column headers
local headerFrame = Instance.new("Frame", frame)
headerFrame.Name = "Headers"
for i = 1, #headers do
	local headerText = headers[i]
	local headerCell = Instance.new("TextLabel", headerFrame)
	headerCell.Text = headerText
	headerCell.Name = headerText
	headerCell.LayoutOrder = i
	local headerSize = Instance.new("UISizeConstraint")
	headerSize.MinSize = Vector2.new(headerWidth[i], 0)
	headerSize.Parent = headerCell
end

-- Finally, add data rows by iterating over each row and the columns in that row
for row = 1, #data do
	local rowData = data[row]
	local rowFrame = Instance.new("Frame", frame)
	rowFrame.Name = "Row" .. row
	for col = 1, #data[row] do
		local cellData = rowData[col]
		local cell = Instance.new("TextLabel", rowFrame)
		cell.Text = cellData
		cell.Name = headers[col]
		cell.TextXAlignment = Enum.TextXAlignment.Left
		if tonumber(cellData) then -- If this cell is a number, right-align it instead
			cell.TextXAlignment = Enum.TextXAlignment.Right
		end
		cell.ClipsDescendants = true
	end
end