How to model a HTML table with column per component in React? - reactjs

React components are awesome when we know how to separate the concern.
However, I find this case really hard to abstract.
| A | B | C |
| A.a | B.a | C.a |
| A.b | B.b | C.b |
| A.c | B.c | C.c |
I have the API that return 1 column per request, eg: [A.a, A.b, A.c]
so normally I will like A, B, C to be a React Component
and render it to it's parent component
However, in this case I cannot easily do that because of the html structure flavor tr per component, not per column.
Does anyone have any idea about this?

Iterate differently, iterate the properties! Use a "RowRenderer" component that loops through all the properties .a, .b, .c given that you know those beforehand. Per property, use a "CellRenderer" that takes an object like A, B, C and the iteration's property-name, and render the cell.

Related

How can I implement instagram-like navigator?

I am new to react native and react navigation. I want to implement a navigator like instagram's navbar. My navbar has 4 Screens, each Screen has several child screens. The routing looks something like this
: : : :
A3 B3 C3 D3
| | | |
A2 B2 C2 D2
| | | |
A1 B1 C1 D1
| | | |
A____B____C____D
Current Behavior
I tried nesting a stack navigator in a tab navigator but its not the behavior I want. When I press A B C D then back, the tab navigator takes me back to A instead of C.
I tried nesting a stack navigator in a Stack navigator, but its not the behavior I want. When I press A B C D then B the stack goes [A,B,C,D,B] instead of [A,C,D,B]
Expected Behavior
How do I implement a Custom navigation with these behaviors using react-navigation:
A,B,C,D then back and it goes to C instead of A
A,B,C,D then B and the stack goes [A,C,D,B] instead of [A,B,C,D,B]

when does binding occur for Compile load and Run

I need to figure out the following:
Using keywords “compile”, “load”, and “run”, describe three different variable bindings in the table below. For each binding (a), (b) and (c), describe a situation for which this kind of binding occurs. (a situation corresponds to a variable in a particular location in a given programming language).
---------------------------------------------------------------------
xxxxxx | Name | Address | Type | value | Lifetime | scope |
--------------------------------------------------------------------
compile
load
run
Not sure about the details you require, but binding occurs when InitializeComponent() is executed in the xaml file

Dynamic partials in angular

I have an angular app that lists items for the user to service, sort of a to-do list. Each to-do requires different fields to complete the task. Making the to-do list is simple. My question is how do I have each to-do item expand to reveal a different set of "sub-partials"? See diagram below:
+---------------------------------------------------------+
| To do #1 |
+---------------------------------------------------------+
| To do #2 |
+---------------------------------------------------------+
| To do #3 |
+---------------------------------------------------------+
User clicks to expand the first to-do:
+---------------------------------------------------------+
| To do #1 |
| |
| +--------------+ +--------------+ +--------------+ |
| | partial A | | partial B | | partial C | |
| +--------------+ +--------------+ +--------------+ |
+---------------------------------------------------------+
| To do #2 |
+---------------------------------------------------------+
| To do #3 |
+---------------------------------------------------------+
User expands 2nd to-do:
+---------------------------------------------------------+
| To do #1 |
+---------------------------------------------------------+
| To do #2 |
| |
| +--------------+ +--------------+ +--------------+ |
| | partial A | | partial D | | partial E | |
| +--------------+ +--------------+ +--------------+ |
+---------------------------------------------------------+
| To do #3 |
+---------------------------------------------------------+
Typically one of the sub-partials might have 3-10 fields. Notice some of them are re-used but some will be different in each to-do item. I expect to have about 30 of the sub-partials.
Is something like this possible to do in a clean way in Angular? I've been looking at ui-router but I don't know that it can do a different set for each to-do. Is there another approach or something better for this? Any suggestions are welcome.
I'd also like to dynamically load the controllers if possible, but that's secondary to the main goal.
If necessary I could have the selected to-do with sub-partials appear in a modal pop-up dialog instead of expanding.
What I've done in my last app is set the name of the sub-partial I want to load as a $scope variable, and then use that variable in an ng-include.
.when('/team/:team', {
'template': "<div ng-include=\"nav.template\"></div>",
'controller': 'TeamCtrl',
}
Then in my controller somewhere:
$scope.nav.template = 'app/partials/team/' + $routeParams.team + '.html';
This let me expand the number of teams who wanted a link quickly without changing my code and adding every team individually. I'm thinking this logic can be expanded to fit your requirement.
Notice that in my example the whole thing is set in the router, but you can also do this from your controller, and set the dynamic ng-include inside another partial.

How to sort an angularFireCollection?

I'm having trouble sorting larger Arrays with an angularFireCollection binding:
$scope.offers = angularFireCollection(new Firebase(url));
while having in my template the code:
<tr ng-repeat="offer in offers | limitTo:100 | orderBy:'createdTimestamp':true">
While the offers.length is < 100, new items are correctly displayed on top. After 100 items, the sorting stops working at all.
The issue is your expression order. "offer in offers | limitTo:100 | orderBy:'createdTimestamp':true" first gets the first 100 elements of offers, then orders. What you want is to order, then limit, so you want to use the string "offer in offers | orderBy:'createdTimestamp':true | limitTo:100". You can see what I mean in the following jsFiddle, where the first list limits the array and then tries ordering while the second orders, then limits: http://jsfiddle.net/qE5P9/1/.

Set position of edit box in the TreeView

In WinForms, I would like to know if it is possible to programmatically set the position of the edit box in the TreeView, and if yes, how ?
Let me give more details.
We have an owner drawn TreeView (System.Windows.Forms.TreeView) with DrawMode set to OwnerDrawAll.
We draw an icon first, then the hierarchy, then the item-related icon and then the text.
[O] +- # Root 1
| |
[X] | +- # Node 1
| | |
[X] | | +- # SubNode 1
| | |
[O] | | +- # SubNode 2
| |
[O] | +- # Node 2
|
[X] +- # Root 2
|
[X] +- # Node 3
On the above graph, the [X] and [O] are the represenations of the first icon, and the # symbol is the representation of the item-related icon.
The problem is, when editing the text using the regular TreeView way, by setting LabelEdit to true, then the Edit box is overlapping the icon (the # symbol on the graph) instead of being beside the icon, because we shifted the text rendering.
Another problem is that the place (rectangle) to click to make the edit box to appear is shifted too.
I tried to set the Indent property with an higher value and then shift my hierarchy, item-related icon and text rendering back to the left to keep it properly aligned, but in this case, indentation is doubled for each node:
It mathematically result in [spacing = level * indent * 2]
Where I need [spacing = indent + (level * indent)]
I just cannot set Indent property individually for each node, so this solution is not valid.
I tried to get the Edit box handle in the OnBeforeLabelEdit event, successfully, but then I figured out that I just cannot do anything usefull with it.
We are thinking about using a custom TextBox and position it ourself on the TreeView, but using the regular already implemented way is prefered.
Thanks in advance.

Resources