-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect heading click and provide clicked cell in table widget (#5)
- Loading branch information
1 parent
f59e163
commit b3b54bc
Showing
2 changed files
with
119 additions
and
24 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
local RunService = game:GetService("RunService") | ||
local ReplicatedStorage = game:GetService("ReplicatedStorage") | ||
local Plasma = require(ReplicatedStorage.Plasma) | ||
|
||
return function(target) | ||
local root = Plasma.new(target) | ||
|
||
local headings = { "Name", "Count" } | ||
local items = {} | ||
for index, letter in { "A", "B", "C", "D", "E" } do | ||
table.insert(items, { letter, 100 - index }) | ||
end | ||
|
||
local connection = RunService.Heartbeat:Connect(function() | ||
Plasma.start(root, function() | ||
Plasma.window("Table", function() | ||
Plasma.row({ | ||
alignment = Enum.HorizontalAlignment.Center, | ||
}, function() | ||
local entries = table.clone(items) | ||
table.insert(entries, 1, headings) | ||
|
||
local tbl = Plasma.table(entries, { | ||
headings = true, | ||
selectable = true, | ||
}) | ||
|
||
local selectedHeading = tbl:selectedHeading() | ||
if headings[selectedHeading] == headings[1] then | ||
-- Sort alphabetically | ||
table.sort(items, function(a, b) | ||
return a[1] < b[1] | ||
end) | ||
elseif headings[selectedHeading] == headings[2] then | ||
-- Sort by count | ||
table.sort(items, function(a, b) | ||
return a[2] < b[2] | ||
end) | ||
end | ||
|
||
local selectedRow, cellIndex = tbl:selected() | ||
if cellIndex == 1 then | ||
-- Remove row if click name | ||
table.remove(items, table.find(items, selectedRow)) | ||
elseif cellIndex == 2 then | ||
-- Shuffle number if click count | ||
selectedRow[cellIndex] = Random.new():NextInteger(1, 100) | ||
end | ||
end) | ||
end) | ||
end) | ||
end) | ||
|
||
return function() | ||
connection:Disconnect() | ||
Plasma.start(root, function() end) | ||
end | ||
end |