lib-ScrollingTable

CreateST

Definition

function ScrollingTable:CreateST(cols, numRows, rowHeight, highlight, parent)

Arguments

cols

This arg is expected to be an array of tables that contain information about each column.
Each column table in the cols array should have the following format:

{
    ["name"] = "Test 1",
    ["width"] = 50,
    ["align"] = "RIGHT",
    ["color"] = { 
        ["r"] = 0.5, 
        ["g"] = 0.5, 
        ["b"] = 1.0, 
        ["a"] = 1.0 
    },
    ["colorargs"] = nil,
    ["bgcolor"] = {
        ["r"] = 1.0, 
        ["g"] = 0.0, 
        ["b"] = 0.0, 
        ["a"] = 1.0 
    }, -- red backgrounds, eww!
    ["defaultsort"] = "dsc",
    ["sortnext"]= 4,
    ["comparesort"] = function (cella, cellb, column)
        return cella.value < cellb.value;
    end,
    ["DoCellUpdate"] = nil,
}

name

The name to use as the column header.

width

The width in pixels that the column should be drawn.

align

(Optional) Alignment of values in the column. Must be one of ( "LEFT" | "RIGHT" | "CENTER" ) Defaults to "LEFT".

color

(Optional) A color object. Defaults to white.

colorargs

(Opional) An array of args that will be passed to the function specified for color. See color object. Defaults to (data, cols, realrow, column, table)

bgcolor

(Optional) A color object. Defaults to clear. In other areas of lib-st, you will find that you can assign a function to return a color object instead. That is not the case with the bgcolor of a column.

defaultsort

(Optional) One of ( "asc" | "dsc" ). Defaults to "asc"

sortnext

(Optional) Must be a valid column number (lua indecies start at 1). Be careful with this value, you can chain across multiple columns, and get yourself into a circular loop.

comparesort

(Optional) A comparator function used to sort values that may not be easily sorted. ex. Dates... and stuff... Be sure to check for and call the comparator of the sortnext column if you wish to keep secondary column sort functionality. See the CompareSort method in Core.lua for an example.

DoCellUpdate

A custom display function.

numRows

This arg defines how many rows you wish the table to show.
If nil, it will default to 12.

rowHeight

This arg defines how tall each row will be.
If nil, it will default to 15.

highligh t

This arg defines the color object for the row highlight to use as you mouse-over a row.
If nil, it will default to mostly-yellow:

{ 
    ["r"] = 1.0, 
    ["g"] = 0.9, 
    ["b"] = 0.0, 
    ["a"] = 0.5, -- important, you want to see your text!
}

In other areas of lib-st, you will find that you can assign a function to return a color object instead. That is not the case with the highlight of a column.

parent

This arg defines the frame that is to be used as the parent frame for the new scrolling table.
If nil, it will default to UIParent

You must login to post a comment. Don't have an account? Register to get one!

  • 4 comments
  • Avatar of verfolgt verfolgt Mon, 23 Nov 2009 20:05:00

    Would be really helpful to have an example of popping up a simple table into a simple AceGUI frame...

    local gui = LibStub("AceGUI-3.0")
    local con = LibStub("AceConsole-3.0")
    local libst = LibStub("ScrollingTable")
    local profFrame = gui:Create("Frame")
    profFrame:SetLayout("Fill")
    local table = libst:CreateST(nil, nil, nil, nil, profFrame)

    Gives "CreateFrame: Couldn't find 'this' in parent object" (I was trying to get the test table into a frame of my own making)

    Last edited on 23 Nov 2009 by verfolgt: markup change
  • Avatar of ddumont ddumont Sun, 23 Aug 2009 13:39:56

    I don't get subscription updates for comments to these pages. Please post comments on the main page, or make tickets for help if you still need it. thanks :)

  • Avatar of minea minea Thu, 16 Jul 2009 21:34:38

    I'm having a little trouble with the parent tag and AceGUI now. I have code like:

    local grp = AceGUI:Create("SimpleGroup")
    grp:SetLayout("Fill")
    f:AddChild(grp)
    

    this create a group frame in my f frame. Later, I build my ST frame and pass it to grp:

    st = ScrollingTable:CreateST( columnHeaders )
    st:EnableSelection(true)
    st:SetWidth(470)
    st:SetHeight(384)
    grp:AddChild( st.frame )
    

    Whe I run this, it doesn't work.

    edi: after a lot of copy-pasting from AceGui internals, I got it working, mostly. Don't take this as a fix, it probably doesn't work completely, but here's what's gotten it to at least appear like a standard ace-gui widget:

    	st.userdata = {}
    	st.SetParent = function(self, parent)
    		local frame = self.frame
    		frame:SetParent(nil)
    		frame:SetParent(parent.content)
    		self.parent = parent
    		--fixlevels(parent.frame,parent.frame:GetChildren())
    	end
    
    	st.SetWidth = function(self, width)
    		self.frame:SetWidth(width)
    		self.frame.width = width
    		if self.OnWidthSet then
    			self:OnWidthSet(width)
    		end
    	end
    
    	st.SetHeight = function(self, height)
    		self.frame:SetHeight(height)
    		self.frame.height = height
    		if self.OnHeightSet then
    			self:OnHeightSet(height)
    		end
    	end
    
    	st.IsVisible = function(self)
    		return self.frame:IsVisible()
    	end
    
    	st.IsShown= function(self)
    		return self.frame:IsShown()
    	end
    	
    	st.SetDisabled = function(self, disabled)
    		self.disabled = disabled
    		if disabled then
    			self.frame:Hide()
    		else
    			self.frame:Show()
    		end
    	end
    
    	st.Release= function(self)
    		local widget = self.frame
    		for k in pairs(widget.userdata) do
    			widget.userdata[k] = nil
    		end
    		for k in pairs(widget.events) do
    			widget.events[k] = nil
    		end
    		widget.width = nil
    		widget.relWidth = nil
    		widget.height = nil
    		widget.relHeight = nil
    		widget.noAutoHeight = nil
    		widget.frame:ClearAllPoints()
    		widget.frame:Hide()
    		widget.frame:SetParent(UIParent)
    		widget.frame.width = nil
    		widget.frame.height = nil
    		if widget.content then
    			widget.content.width = nil
    			widget.content.height = nil
    		end
    		del(widget,widget.type)
    	end
    	
    	st.Fire = function(self, name, ...)
    		if self.events[name] then
    			local success, ret = safecall(self.events[name], self, name, ...)
    			if success then
    				return ret
    			end
    		end
    	end
    	
    	st.OnRelease= function (self)
    		self.frame:ClearAllPoints()
    		self.frame:Hide()
    		self:SetDisabled(false)
    	end
    
  • Avatar of minea minea Thu, 16 Jul 2009 00:40:33

    re colorargs

    what are being passed in by default? specifically, I want to color cell data based on it's row's column 3.

    can I do

    ["colorargs"] = {"row"}
    


    and then, in the function, switch on

    row.cols[3].value
    

    or if not, how do I do it? :)

    edit: I figured out the color arguments. you can't abstractly specify cell data at the column level. you have to do it when you create the table data's rows.
    Basically, the usage is like:

    --myAddon.lua
    ST_data = {}
    ST = ...CreateST...
    
    --[[ convert internal data format to lib-st's format ]]--
    function ST_ProcessData( int_data )
     --[[ for example if int_data represents a 2 col/3 row table, 
           and is {{"A1","A2"},{"B1","B2"},{"C1","C2"}}
           and we want to color code the first column based on the first column
    ]]--
      ST_data = {}
      for j,row in pairs(int_data)
        ST_data[j] = {}
        for k,col in pairs(row)
          if k == 1 then
            ST_data[j].cols[k] = { value=col, color= handle_ColorFunc, colorargs={col}}
          else
            ST_data[j].cols[k] = { value=col }
          end
        end
      end
    end
    
    function ST_Update( int_data )
      ST_ProcessData( int_data )
      ST:SetData(ST_data)
    end
    
  • 4 comments