Knockout binding a font awesome icon to a property - data-binding

I'm attempting to display a font awesome icon based on a property whilst looping through a knockout observable array.
Current code:
<tbody data-bind="foreach: TimeToPutAwaySummary">
<tr class="noOfPeopleRequiredRow">
<td data-bind="text: $data.IsOptimumNoOfPeople ? '***' + $data.NoOfPeopleRequiredText + '***' : $data.NoOfPeopleRequiredText">
</td>
<td style="text-align: right" data-bind="text: $data.Time"></td>
</tr>
</tbody>
This currently works such that it outputs:
1 Person Required
*** 2 Person Required ***
3 Person Required
4 Person Required
5 Person Required
However, I want to display a font awesome icon instead of the '***' i.e. something like this:
1 Person Required
(font awesome icon) 2 Person Required
3 Person Required
4 Person Required
5 Person Required
I've tried the following but that doesn't display an icon:
<tbody data-bind="foreach: TimeToPutAwaySummary">
<tr class="noOfPeopleRequiredRow">
<td data-bind="text: $data.IsOptimumNoOfPeople ? '***' + $data.NoOfPeopleRequiredText + '***' : $data.NoOfPeopleRequiredText">
<span data-bind="visible: IsOptimumNoOfPeople"><i class="fa fa-spinner" aria-hidden="true"></i></span>
</td>
<td style="text-align: right" data-bind="text: $data.Time"></td>
</tr>
</tbody>
I also tried to replace the span tag with a p tag.

you're using <td data-bind="text: $data....> on your td, this wil overwrite all content inside the element thus your icon-span-tag is ignored & removed. try moving the data-bind away from your td like following copy/paste code:
<td>
<span data-bind="text: $data.IsOptimumNoOfPeople ? '***' + $data.NoOfPeopleRequiredText + '***' : $data.NoOfPeopleRequiredText"></span>
<span data-bind="visible: IsOptimumNoOfPeople"><i class="fa fa-spinner" aria-hidden="true"></i></span>
</td>
Or better yet just remove the data-bind on your td since that's going to be replaced with your font-awesome icon.. :)

Related

semantic ui - how to style table headings

So I have built a table in semantic-ui. very simple. however styles dont seem to apply to my table in certain aspects and i cant get the headings to map over the columns. see the below screenshot
the L column is fine but the others are a bit wonky and name is just well off. how can i adjust the styles so make this work?
I have tried to add a width to the div my table sits in but it just extends it without altering the table body or head
here is the code:
<div className="tableContainer">
<h1> Table </h1>
<table className="ui striped table">
<thead>
<tr>
<th className="headings">Ranks</th>
<th className="headings">Name</th>
<th className="headings">P</th>
<th className="headings">W</th>
<th className="headings">L</th>
</tr>
</thead>
<tbody>
{this.props.players.sort(function(a, b) {
return (a.rank) - (b.rank);
}).map(function(player, index) {
index +=1;
return <tr key={index} className="table-rows">
<td className="stats">{player.rank}</td>
<td className="stats">{player.name}</td>
<td className="stats">{player.played}</td>
<td className="stats">{player.wins}</td>
<td className="stats">{player.losses}</td>
</tr>
}, this)}
</tbody>
</table>
</div>
If you are working in Reactjs, you should use Semantic-UI's reactjs package: Semantic-UI React. In the Table section, you can see that certain properties are passed through props. You can set the column number with columns prop. And under the Table.Header tab, you can see that there's a className prop. You can use it to style your header. For reference, visit: Semantic-UI React Table.

Twitter bootstrap - Make a table row inactive

Hi I want to make a row in a table inactive. Even if it is easy to hack by myself and add a custom css with the same colour of the inactive elements of my current theme I think it can be handles by bootstrap itself.
Any suggestions?
Bootstrap has a few elements you might find helpful:
Use contextual classes to change row colors:
<!-- On rows -->
<tr class="active">...</tr>
<tr class="success">...</tr>
<tr class="warning">...</tr>
<tr class="danger">...</tr>
<tr class="info">...</tr>
<!-- On cells (`td` or `th`) -->
<tr>
<td class="active">...</td>
<td class="success">...</td>
<td class="warning">...</td>
<td class="danger">...</td>
<td class="info">...</td>
</tr>
http://getbootstrap.com/css/#tables-contextual-classes
Use contextual colors to change the color of text:
<p class="text-muted">...</p>
<p class="text-primary">...</p>
<p class="text-success">...</p>
<p class="text-info">...</p>
<p class="text-warning">...</p>
<p class="text-danger">...</p>
http://getbootstrap.com/css/#helper-classes-colors
The disabled element is primary for form elements and buttons. Check that out here,
I've created a custom class table-inactive:
.table-inactive td {
background-color: #ececec;
color: #b9b9b9;
}
Does the table row contain any inputs? If so, add the disabled HTML5 attribute to the input and perhaps make the text in that row greyed out to show it is inactive? Just an idea..
I.E.
<tr>
<td style="color:grey;">Sample Text</td>
<td><input type="text" disabled/></td>
</tr>
I have worked with Twitter Bootstrap a bit and did not see any of these features though.
Bootstrap 4 requires you to add "table-" to the class.
<tr class="table-danger">...</tr>
https://getbootstrap.com/docs/4.4/content/tables/#contextual-classes

Smarty - How to hide questions under each section in a long form

I'm very new to smarty and I'm trying to figure out a way to hide questions under each section title in a long form. I would need to add some id or class to the section name and some div to wrap to the questions under this specific section title so I can target them in css or js, but I'm breaking my head to find a way to do that with smarty.
Here is my code:
{if !empty($questionList)}
{foreach from=$questionList key='section' item='questions'}
{if !empty($section) }
<tr class="ow_tr_first"><th colspan="3" class="section_label">{text key="base+questions_section_`$section`_label"}</th></tr>
{/if}
{foreach from=$questions item='question' name='question'}
<tr class="{cycle values='ow_alt1,ow_alt2'} {if $smarty.foreach.question.last}ow_tr_last{/if}">
<td class="ow_label">
{label name=$question.name}
</td>
<td class="ow_value">
{input name=$question.name}
<div style="height:1px;"></div>
{error name=$question.name}
</td>
</tr>
{/foreach}
<tr class="ow_tr_delimiter"><td></td></tr>
{/foreach}
{/if}
Any help would be awesome :)
You can try to use the current iteration of the first foreach to create unique identifiers/classes:
i.e.
{foreach from=$questionList key='section' item='questions' name='loop'}
{if !empty($section) }
<tr class="ow_tr_first"><th colspan="3" class="section_label" id="question{$smarty.foreach.loop.iteration}">{text key="base+questions_section_`$section`_label"}</th></tr>
{/if}
<tr class="question{$smarty.foreach.loop.iteration}_child {cycle values='ow_alt1,ow_alt2'} {if $smarty.foreach.loop.last}ow_tr_last{/if}">
So you willl end up with something like this:
<tr><th class="section_label" id="question1"></th></tr>
<tr class="question1_child">....</tr>
<tr class="question1_child">....</tr>
<tr class="question1_child">....</tr>
<tr><th class="section_label" id="question2"></th></tr>
<tr class="question2_child">....</tr>
<tr class="question2_child">....</tr>
<tr class="question2_child">....</tr>
and so on. That would be quite easy to target with css or javascript, i.e. hiding all .question1_child or showing all #id_name+'_child' when a certain .section_label is pressed

How to create zebra-stripe CSS with TAL?

How can I use Chameleon or Zope Page Templates to easily create CSS zebra striping? I want to add odd and even classes to each row in a table, but using a condition with repeat/name/odd or repeat/name/even looks rather verbose even with a conditional expression:
<table>
<tr tal:repeat="row rows"
tal:attributes="class python:repeat['row'].odd and 'odd' or 'even'">
<td tal:repeat="col row" tal:content="col">column text text</td>
</tr>
</table>
This gets especially tedious if you have multiple classes to calculate.
The Zope Page Templates implementation for the repeat variable has an under-documented extra parameter, parity, than gives you the string 'odd' or 'even', alternating between iterations:
<table>
<tr tal:repeat="row rows"
tal:attributes="class repeat/row/parity">
<td tal:repeat="col row" tal:content="col">column text text</td>
</tr>
</table>
This is also much easier to interpolate into a string expression:
tal:attributes="class string:striped ${row/class} ${repeat/row/parity}"
This works in Chameleon as well.

Rails - using CSS on some condition

I have a requirement to make a app that has a view. In that view I need to check a condition and if it is true, then need to color a table row appropriately. The easiest way to do this is just to use different header in the view. But how to do it if I want to keep all my styling information in CSS?
If it's just a row you want to colour then you can do it in the view, no need to mess around with headers:
<tr class="<%= "blue" if some_condition %>">
<td>Your text</td>
</tr>
Or:
<% if some_condition %>
<tr class="blue">
<% else %>
<tr class="red">
<% end %>
<td>Your text</td>
</tr>
application_helper.rb
def my_color_for(condition)
if condition
'white'
else
'blue'
end
end
view.haml
- #array.each do |a|
%tr{class: my_color_for(a.value)}

Resources