Search Unity

[RELEASED] UI Table

Discussion in 'Assets and Asset Store' started by bourriquet, Mar 14, 2019.

  1. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    If your XML is in Resources, you can access it with Resources.Load()
    Then you can convert the TextAsset into a StringReader.
    So that's:

    Code (CSharp):
    1.     public class XML2ListConverter : MonoBehaviour
    2.  
    3.         public List<MyClass> myList;
    4.  
    5.         void Start()
    6.         {
    7.             XmlSerializer serializer = new XmlSerializer(typeof(List<MyClass>));
    8.             TextAsset textAsset = Resources.Load("path_to_xml");
    9.             using (var reader = new StringReader(textAsset.text))
    10.             {
    11.                 myList = (List<MyClass>)serializer.Deserialize(reader);
    12.             }
    13.         }
    14.  
    15.     }
    Keep in mind the path_to_xml is relative to the containing Resources folder.
     
  2. BennyTan

    BennyTan

    Joined:
    Jan 23, 2014
    Posts:
    141
    Hi, before i buy this plugin, could i check, there seems to be a fixed list for the cell types. Is there a dropdown list option for the cell types?
     
  3. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    Hi @BennyTan
    Yes, there is a dropdown list cell type for enum fields.
    The cell types list is extendable. You can inherit the CellType class and create new cell type objects. They will automatically be added to the list of available types.
     
  4. Friction

    Friction

    Joined:
    Jan 6, 2015
    Posts:
    18
    Hello @bourriquet ,
    Thank you for this great asset.
    I want to add columns at runtime (via script), is it possible?
     
  5. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    Hi @Friction
    The code isn't really thought for that, but it still works. You have to add a small change though: in TableColumnInfo.cs, add a constructor as such:

    Code (CSharp):
    1. public TableColumnInfo(Table table, string fieldName, float width, bool useRelativeWidth, TableCell cellPrefab, string columnTitle)
    2. {
    3.     this.table = table;
    4.     this.fieldName = fieldName;
    5.     this.width = width;
    6.     this.useRelativeWidth = useRelativeWidth;
    7.     this.cellPrefab = cellPrefab;
    8.     this.columnTitle = columnTitle;
    9. }
    then, in your code, you can do:

    Code (CSharp):
    1. table.columns.Add(
    2.     new TableColumnInfo(table, fieldName, width, isRelativeWidth, cellPrefab, columnName));
    I'll think about a clean way to support that for the next update.
     
    Friction likes this.
  6. Friction

    Friction

    Joined:
    Jan 6, 2015
    Posts:
    18
    Hello again,

    Thank you for your kind reply. I've one more question.
    Can I add list elements to table as columns?
     
  7. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    @Friction
    There is currently no Cell that is adapted to list properties. Lists are by definition of variable size, which means it's unclear how it should be fitted in a column.
    You can, however, code your own custom Cell Type class to fit your needs in that regard.
     
    Friction likes this.
  8. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    @Friction
    Actually, if you just want a simple print out of the list as text in a Label Cell, that can be easily done.
    In LabelCell.cs, add

    Code (CSharp):
    1. using System.Linq;
    then replace the UpdateContent function with this one:

    Code (CSharp):
    1. public override void UpdateContent()
    2. {
    3.     if (property == null || property.IsEmpty)
    4.         return;
    5.     object o = property.GetValue(obj);
    6.     if (o == null)
    7.         label.text = "null";
    8.     else if (Table.IsCollection(o.GetType()))
    9.         label.text = string.Join(", ", (o as IEnumerable).OfType<object>().Select(obj => obj.ToString()).ToArray());
    10.     else
    11.         label.text = o.ToString();
    12. }
    That actually totally makes sense so I will add that in an update now.
     
    Last edited: Feb 24, 2020
    Friction likes this.
  9. dougdodd

    dougdodd

    Joined:
    Apr 18, 2014
    Posts:
    32
    How do I set cells using TextMeshPro assets? The dropdown list is Text Cell, Input Cell or Input Cell expandable. Can I make a TMP asset and add it to that list?
     
  10. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    Hi @dougdodd
    Extract the file Assets/RuntimeGUITable/TextMeshPro Addings.unitypackage in your project and there will be an additional TMP cell type in the list.
     
    Last edited: Feb 24, 2020
  11. vihist

    vihist

    Joined:
    Sep 7, 2017
    Posts:
    2
    The header is hidden when i scroll the table. How to show the header when scroll?
    Thx!
     
  12. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    Hi @vihist
    Sorry a scrollable table with fixed headers line feature is not yet available. I'll work on this for the next update.
    Thanks for the suggestion.
     
  13. misato

    misato

    Joined:
    Aug 5, 2012
    Posts:
    23
    Hi I am having a table with selectable rows but it seems that I can select everything (including headers) except for the last row of the table. What am I missing?
    It is a simple table with an image and some text per row. Also not scrollable, and always having 10 rows (so not even super big)

    EDIT: alright I found the issue but I am not sure this will break anything else:

    In the Table.cs script, at line 224 function HandleInputs you have this:

    Code (CSharp):
    1. if (Input.GetKeyUp(KeyCode.UpArrow))
    2.     selectedRow = Mathf.Max(selectedRow - 1, 0);
    3. else if (Input.GetKeyUp(KeyCode.DownArrow))
    4.     selectedRow = Mathf.Min(selectedRow + 1, elementCount-1);
    it should be changed to:

    Code (CSharp):
    1. if (Input.GetKeyUp(KeyCode.UpArrow))
    2.     selectedRow = Mathf.Max(selectedRow - 1, 1);
    3. else if (Input.GetKeyUp(KeyCode.DownArrow))
    4.     selectedRow = Mathf.Min(selectedRow + 1, elementCount);
    The reason for this change is that row 0 is the header of the table. I don't know if there is a way to disable headers. In that case it shouldbe checked here if there is header or not and change those numbers acordingly.
     
    Last edited: Dec 13, 2019
  14. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    Hi @misato
    Wow. Thanks for fixing it for me!
    There is no way to disable headers so it's a plain and simple bug. This has never been reported before, so I guess few people use the selectable feature.
    I'll upload the fix this week.
    Thanks again!
     
  15. misato

    misato

    Joined:
    Aug 5, 2012
    Posts:
    23
    Not a problem! :D At the end I needed to disable that code because in my case I use Rewired and then it got double presses. I wonder if there's a better way to check if you are using the standard Unity input or inControl/Rewired (I'm still fairly new to Unity). But in any case I'm happy to help!

    EDIT: I forgot to thank you for this wonderful asset!!! It really saved me a lot of time making a table for a leaderboard in my game.
     
    Last edited: Dec 20, 2019
  16. nekkoriv

    nekkoriv

    Joined:
    Jul 30, 2018
    Posts:
    1
    Hi Bourriquet, is there a way to have the collection properties be rows and the data be columns? Basically, are we able to make horizontal tables? That would be immensely useful in solving the problem I purchased this in hopes to solve.
     
  17. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    Hi @nekkoriv
    Unfortunately that is not currently possible. But that's a very good idea, so I'll be working on it. If your problem can wait for maybe a week (Unity's approval can take 2-3 days), I'll let you know.
     
  18. Jan85

    Jan85

    Joined:
    Aug 18, 2013
    Posts:
    3
    Hello Bourriquet,
    I got your UI Table and enjoy how simple it is to use it even for beginner programmer as myself.
    I managed to connect the table to a list that I am populating from SQLite database.

    What I am struggling with is reading which row was selected by the user (ideally reading the ID column or at least row index) and trigger click event so I can work with the information further in the application.

    Additionally I would also need the table to be scrollable with the header row locked on top always showing even after the table is scrolled down – someone else here was already asking for the same thing.

    In attachment is the code I use to fill the table. I need to read the “ID” when user click a line and trigger an event. And ideally have the first line clicked when table is loaded. Could you help me with that please?

    Thank you in advance
    Jan
     

    Attached Files:

  19. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    Hi @Jan85
    For reading the selected row, use Table.SelectedRow. The user can only select entire rows. If you want to know the column selected, you will have to work with Unity UI's selection system.
    Scrollable table with fixed header is not supported. That's a good idea (arguably more useful than the current scrollable option actually) but I don't think I can do it in a short time. In the meantime, you could workaround by duplicating the table:
    - one for the headers, populated with an empty collection and set non-scrollable
    - one for the data, with the real collection and set to scrollable, with the headers hidden in some way
    Let me know if you have further questions.
     
  20. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    Hi @nekkoriv
    The 1.6 version, that was just approved, contains a "Horizontal" option. Let me know if it fills your needs.
     
  21. Jan85

    Jan85

    Joined:
    Aug 18, 2013
    Posts:
    3

    Thank you I appreciate your help. I managed to get the ID from the table and update it on click. And for scrolling I am using table with header covered by text boxes with header names. It’s not optimal but works fine for me.
     
  22. Eran82

    Eran82

    Joined:
    Nov 22, 2013
    Posts:
    1
    Thanks for the great asset!

    +1 for scrollable table with fixed headers ;-)
     
    bourriquet likes this.
  23. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    For info, I am working on the fixed headers / scrollable content, but that is quite a refactoring (@Eran82, @Jan85).
    In the meantime, I submitted an update that has the option to not display the header row + an important bug fix with collection size changes. It should be up this week.
     
  24. Alex_F

    Alex_F

    Joined:
    Mar 4, 2014
    Posts:
    10
    I have just purchased the asset and it's being extremely laggy in the Editor. 2019.2.17. It happens as soon as I add the collection.
     
    Last edited: Apr 8, 2020
  25. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    Hi @Alex_F .
    I'll have a look. A few questions to make sure I can reproduce.
    How big is your collection?
    Does it happen in Play Mode or in Edit Mode?
    Even before you add the columns?
    Windows or Mac?
     
  26. Alex_F

    Alex_F

    Joined:
    Mar 4, 2014
    Posts:
    10
    It happens with empty collection. Editor Mode. Even before columns. Windows.
    I'm happy to provide more info.
     
  27. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    @Alex_F
    Is the example scene laggy as well?
     
  28. Alex_F

    Alex_F

    Joined:
    Mar 4, 2014
    Posts:
    10
    Yes, it is. What can be the cause? Do you test only on Mac?
     
  29. Alex_F

    Alex_F

    Joined:
    Mar 4, 2014
    Posts:
    10
    Any update?
     
  30. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    Hi @Alex_F . Sorry for the late response.
    I can see small spikes to 40ms in the editor when dragging up and down the Table component in the inspector (repainting the inspector is costly), but nothing to the extend of what you are describing.
    I will need more information about your setting (target platform, quality settings, your machine...).
    Or even better, a sample project to reproduce, if that's feasible on your side.
    Sorry for the inconvenience. If you don't want to go through this trouble and would prefer a refund, I totally understand. Though I would definitely prefer to get to the bottom of it..
     
  31. Alex_F

    Alex_F

    Joined:
    Mar 4, 2014
    Posts:
    10
    Hi! Sorry, I can't reply here often. But it's possible that we have a talk in skype or zoom and I show you what happens. I will continue using your table because it's easy. But the Editor UI is very slow.
     
  32. sericaer

    sericaer

    Joined:
    May 4, 2018
    Posts:
    6
    also waiting for fixed headers table, Thanks a lot!
     
  33. YuuYuuV

    YuuYuuV

    Joined:
    Oct 7, 2019
    Posts:
    6
    Hi @bourriquet

    I copied the example scene and then re-attached the enemiesManager to the collection of Table (Script). Then I defined the column info according to "Getting Started: Create the Table".

    When I try to run the scene (Unity 2019.2), I can input numerical values for items such as HP, but the value of EnemiesManager does not change with the input.

    I suspect that this is probably due to a broken connection between TableScript and EnemiesManager. But I don't know how to fix it.

    I'm really in trouble!
    Any advice would be appreciated.
     
  34. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    Hi @YuuYuuV
    I recently noticed a problem with Unity 2019 where the Cell's Interactable value gets set to false for some reason.
    If that's it, you'll have to create a Style for your column (with the gear button), then right-click the Table component and choose Initialize, then save your scene.
    Please let me know if that fixed it.
     
    Last edited: May 24, 2020
  35. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    Hi @sericaer
    I'm finally getting there. It's functional and I just need to test it thoroughly before submitting, and also implement auto-conversion from the old version, as it's a complete refactoring.
    I can send it to you via email if you want to use it before it's out.
     
  36. YuuYuuV

    YuuYuuV

    Joined:
    Oct 7, 2019
    Posts:
    6
    Your solution is correct. The problem was solved. Thanks!!
     
    bourriquet likes this.
  37. sericaer

    sericaer

    Joined:
    May 4, 2018
    Posts:
    6
    Thanks!! my email is sericaer@outlook.com
     
  38. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    @sericaer @Jan85 @Eran82
    Scrollable with fixed headers is now out, version 1.9.
    Please let me know if you encounter any issues with it.
     
  39. sericaer

    sericaer

    Joined:
    May 4, 2018
    Posts:
    6
    Table throw Exception when select Update cell content.
    I send the demo to your email, could you check this problem? Thanks a lot!

    ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
    System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <437ba245d8404784b9fbab9b439ac908>:0)
    System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <437ba245d8404784b9fbab9b439ac908>:0)
    System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <437ba245d8404784b9fbab9b439ac908>:0)
    UnityUITable.TableCell.get_obj () (at Assets/RuntimeGUITable/Scripts/Cells/TableCell.cs:69)
    UnityUITable.LabelCell.UpdateContent () (at Assets/RuntimeGUITable/Scripts/Cells/Label/LabelCell.cs:33)
    UnityUITable.TableCell.Initialize () (at Assets/RuntimeGUITable/Scripts/Cells/TableCell.cs:128)
    UnityUITable.TableRow.CreateCell (UnityUITable.TableColumnInfo column, System.Int32 columnIndex) (at Assets/RuntimeGUITable/Scripts/TableRow.cs:90)
    UnityUITable.TableRow.CreateCells () (at Assets/RuntimeGUITable/Scripts/TableRow.cs:65)
    UnityUITable.TableRow.Initialize (System.Int32 rowIndex) (at Assets/RuntimeGUITable/Scripts/TableRow.cs:52)
    UnityUITable.Table.UpdateRows (System.Int32 expectedNbRows, System.Int32 actualNbRows, System.Int32 bottomRows, System.Int32 titleRows) (at Assets/RuntimeGUITable/Scripts/Table.cs:608)
    UnityUITable.Table.UpdateContent () (at Assets/RuntimeGUITable/Scripts/Table.cs:592)
    UnityUITable.Table.Update () (at Assets/RuntimeGUITable/Scripts/Table.cs:434)
     
    Last edited: Jun 3, 2020
  40. sericaer

    sericaer

    Joined:
    May 4, 2018
    Posts:
    6
    Table throw Exception when select Update cell content.
    I send the demo to your email, could you check this problem? Thanks a lot!
     
  41. unity_a2020

    unity_a2020

    Joined:
    Jun 1, 2020
    Posts:
    1
    Trying to compile but got the errors:
    Assets/RuntimeGUITable/Scripts/TableRow.cs(55,70): error CS1061: 'Table' does not contain a definition for 'IsScrollable' and no accessible extension method 'IsScrollable' accepting a first argument of type 'Table' could be found (are you missing a using directive or an assembly reference?)
    Assets/RuntimeGUITable/Scripts/Table.cs(450,8): error CS0103: The name 'IsScrollable' does not exist in the current context
    Assets/RuntimeGUITable/Scripts/Table.cs(526,8): error CS0103: The name 'IsScrollable' does not exist in the current context

    Error building Player because scripts had compiler errors
    Build completed with a result of 'Failed' in 3 seconds (3195 ms)
    UnityEditor.BuildPlayerWindow:BuildPlayerAndRun() (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPlayerWindow.cs:136)
    UnityEditor.BuildPlayerWindow+BuildMethodException: 4 errors
    at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x002af] in /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPlayerWindowBuildMethods.cs:194
    at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] in /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPlayerWindowBuildMethods.cs:95
    UnityEditor.BuildPlayerWindow:BuildPlayerAndRun() (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPlayerWindow.cs:136)

    If I delete the folder RuntimeGUITable, then there is no compilation error.
     
  42. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    Hi @sericaer , @unity_a2020 ,
    As mentioned via emails, those 2 bugs have been fixed, and the update is now online.
    Please let me know if there are any other issues.
    Thanks!
     
  43. sericaer

    sericaer

    Joined:
    May 4, 2018
    Posts:
    6
    Table throw exception when click the colum to sort, which colum bind to a "internal" member.

    IndexOutOfRangeException: Index was outside the bounds of the array.
    UnityUITable.SortingState.KeySelector (System.Object elmt) (at Assets/RuntimeGUITable/Scripts/Data/SortingState.cs:34)

    to solve this issue, the BindingFlags should be added.

    Code (CSharp):
    1. public object KeySelector(object elmt)
    2.  {
    3.         PropertyOrFieldInfo property = new PropertyOrFieldInfo(elmt.GetType().GetMember(sortingColumn.fieldName, BindingFlags.Instance |BindingFlags.NonPublic |BindingFlags.Public)[0]);
    4.          return property.GetValue(elmt);
    5.    }
     
    Last edited: Jun 9, 2020
  44. Bogdenz

    Bogdenz

    Joined:
    Oct 17, 2019
    Posts:
    4
    Looks like a neat asset, but do you offer a non per seat license? Unfortunately I can't use it otherwise.
     
  45. amrullakhan

    amrullakhan

    Joined:
    Oct 28, 2017
    Posts:
    5
    Hi, I am curious in this asset. Wanted to know
    1. How many types of UI elements it allows in table cells. My main work will be with images aand inputfields.
    2. Does it allow row span and column span?
    Thanks and regards,
    Khan
     
  46. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    Hi @amrullakhan. Thanks for your interest.
    1. Image fields and Input fields are supported out of the box, like every basic UI elements (Label, Slider, Dropdown, Toggle). You can create custom cell types for other needs.
    2. No, it's a simple table with 1 cell = 1 row & 1 col. The emphasis was on automatically populating the table from a collection, so custom cells like this are not the kind of use case I targeted.
     
  47. amrullakhan

    amrullakhan

    Joined:
    Oct 28, 2017
    Posts:
    5
    @bourriquet thanks for the quick response. I really need col span and row span kind of features too. If you are aware of any asset please do let me know. Thanks alot.
     
  48. UKMasters

    UKMasters

    Joined:
    Jun 8, 2020
    Posts:
    2
    @bourriquet This looks like a potentially really useful asset, but it slows down Unity so much that it's unusable. This is using a collection with only 3 things in it and the slow down happens as soon as I add the table, before I've added any columns. I am using Unity 2020.1.1f1. My project is a very simple test project and does nothing complex.

    I've just tested based on the sample scene you provide too and it is exactly the same. Extremely slow.

    Do you have any idea of what the problem could be?
     
    Last edited: Sep 10, 2020
  49. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    @UKMasters Thanks for your message. It seems to depend on the computer rather than the Unity version, and I found a computer where I could reproduce it. So it should be fixed by next week.
     
  50. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    @UKMasters The new version that is just out (1.10) should have no more lag when inspecting the script. Please let me know if you encounter any issue.