how to right justify values in table cells

egurevich

Member
I would like so that certain columns in the table with the data are right justified as opposed to the default left justified. Where can I change that?
 

egurevich

Member
I need more help with this. Can you send me some sample code with would right justify columns of specific fields in the database? I would have to specify the field by its name.
 

DebbieS

DaDaBIK Guru
In the sample code parts below, italics is EXISTING CODE in the file(s) noted and the bold text is what should be added.

There is already a content type in DaDaBIK named "numeric". If your fields are numeric, I'd just make those fields the numeric content type and add code to business_logic.php to right align those fields (on or about 2833):

if ($field_content == "email"){
$field_to_display = "<a href=\"mailto:".$field_value."\">".$displayed_part."</a>";
} // end if

elseif ($field_content == "numeric"){
$field_to_display = "<div style=\"text-align:right;\">".$displayed_part."</div>";
} // end elseif

elseif ($field_content == "url"){
$field_to_display = "<a href=\"".$field_value."\">".$displayed_part."</a>";
} // end elseif


If you cannot simply use the numeric content type, then I'd suggest adding a new field type to your installation rather than writing code for specific fields (much easier to implement).


To add a new field type, open include/internal_table.php and add your new field type name into the list where you want it to appear:

$int_fields_ar[2][3] = "text/text_right/textarea/rich_editor/password/insert_date/update_date/date/select_single/generic_file/image_file/ID_user/unique_ID";

In this example, I've added the type "text_right" separated by a slash right after the text type. This adds the new type to the drop-down list in the Admin Interface Configurator.

Then open include/business_logic.php and inside the get_field_correct_displaying function (on or about line 2812), add this new field type case:

...case "rich_editor":
$field_to_display = $field_value;
break;

case "text_right":
if ($display_mode == "results_table") {
$field_to_display = "<div style=\"text-align:right;\">".$field_value."</div>";
}
else{
$field_to_display = $field_value;
} // end else

default: // e.g. text, textarea and select sinlge
if ($display_mode === .....


This tells DaDaBIK that whenever it encounters a field which is set to "text_right" and the display is the results table, apply the right-alignment to the text.

Change the fields you want right aligned in the interface configurator to this new type and you're done like dinner.

If you rather want to add a new content type, you need to add the if for the new content type to every field type where the content type could be used. Easier to add field type.

 

egurevich

Member
I did everything using your option number 2, but it did not work.
The problem is that when text is inside a table in order for it to be displayed right justified from the right side the <TD> tag of that table data cell has to be modified to be <TD ALIGN="right" DIR="rtl">. And that does not happen. I need to change the code that would modify the <TD> tag around the cells whose text type is set to text_right.
How can I do that?
Thanks
Eli
 

DebbieS

DaDaBIK Guru
What doctype are your pages referencing? A div tag instructing the browser to right align text inside the div works in all browsers I've tested.

Your initial request did not indicate or refer to anything other than right aligned so I did not include anything for changing direction of text.

Just add the css value for text direction of direction:rtl; to the div tag in my example. So the whole opening div tag will read <div style="text-align:right;direction:rtl;">.....

Ensure you have changed the fields which are to be right aligned to the new field type or you will not see any change in behavior. I looked at your site (url from previous post) and there do not appear to be any fields which have the div tag applied to them.

 

egurevich

Member
I have a few columns with Hebrew text in them. Hebrew is read from Right to Left so I need the text to be right justified.

I modified the code in business_logic.php with the direction tag and also set all of those fields to the text_right_justified type, but neither thing helped.

You can see the site here. Look at the 4 columns with Hebrew text on the right side of the table. All of them are left justified.

The code looks like this:

case "text_right_justified":
if ($display_mode == "results_table") {
$field_to_display = "<div style=\"direction: rtl; text-align:right;\">".$field_value."</div>";
}
else{
$field_to_display = $field_value;
} // end else


Do I need to add something to the header.php file that it will interpret this style correctly?
 

DebbieS

DaDaBIK Guru
Where have you placed the case "text_right_justified" in business_logic.php?

You may wish to change the case to read as follows instead of only for results table:

case "text_right_justified":
$field_to_display = "<div style=\"direction: rtl; text-align:right;\">".$field_value."</div>";
break;

Also note, for some reason, I missed the closing "break;" line in my original post. Thank the cold medication for the lack of attention to details.

Because of the language thing, you might want to make a couple other changes to your app:

Add a new case to your build_forms function (copy the case section including the break; for text, id_user, etc) and paste it between the existing break and case "generic_file":

case "text_right_justified":
$form .= "<td class=\"td_input_form\">".$select_type_select."<input type=\"text\" style=\"direction: rtl; text-align:right;\" name=\"".$field_name_temp."\"";
if ($fields_labels_ar[$i]["width_field"] != ""){
$form .= " size=\"".$fields_labels_ar[$i]["width_field"]."\"";
} // end if
$form .= " maxlength=\"".$fields_labels_ar[$i]["maxlength_field"]."\"";
if ($form_type == "update" or $form_type == "ext_update"){
if ($show_edit_form_after_error === 1){
if (isset($_POST[$field_name_temp])) {
$form .= " value=\"".htmlspecialchars(stripslashes($_POST[$field_name_temp]))."\"";
} // end if
} // end if
else {
$form .= " value=\"".htmlspecialchars($details_row[$field_name_temp])."\"";
} // end else
} // end if
if ($form_type == "insert"){
if ($show_insert_form_after_error === 1 && isset($_POST[$field_name_temp])) {
$form .= ' value="'.htmlspecialchars(stripslashes($_POST[$field_name_temp])).'"';
} // end if
else {
$form .= " value=\"".$fields_labels_ar[$i]["prefix_field"].$fields_labels_ar[$i]["default_value_field"]."\"";
} // end else
} // end if
$form .= ">";
if (($form_type == "update" or $form_type == "insert") and $fields_labels_ar[$i]["content_field"] == "city"){
$form .= "<a name=\"".$field_name_temp."\" href=\"#".$field_name_temp."\" onclick=\"javascript:fill_cap('".$field_name_temp."')\">?</a>";
} // end if
$form .= "</td>"; // add the second coloumn to the form
break;

I don't know how this will work as I have no idea how to enter rtl text into forms, so you'll have to play around with that.

Also, add this field type to the multiple search form type list if you wish them to be included in the general search we worked on.

 

egurevich

Member
Actually it was the missing break; that was causing it not to work right. Once I added the break everything worked correctly. The final case in business_logic.php looks like this:

case "text_right_justified":
if ($display_mode == "results_table") {
$field_to_display = "<SPAN DIR=rtl><div style=\"text-align: right;\">".$field_value."</div></SPAN>";
}
else{
$field_to_display = $field_value;
} // end else
break;
 

egurevich

Member
Well I tried to modify the case code in order to get the column width to work using word_wrap but it's not happening.

My case in business_logic.php now looks like this:

case "text_right_justified":
if ($display_mode == "results_table") {
$displayed_part = wordwrap($field_value, $word_wrap_col, "\n", $enable_word_wrap_cut);
//$field_to_display = "<SPAN DIR=rtl><div style=\"text-align: right;\">".$field_value."</div></SPAN>";
$field_to_display = "<SPAN DIR=rtl><div style=\"text-align: right;\">".$displayed_part."</div></SPAN>";
}
else{
$field_to_display = $field_value;
} // end else
break;

Help me please. I wonder what's wrong here.
 

DebbieS

DaDaBIK Guru
have you tried to use:

case "text_right_justified":
if ($display_mode == "results_table") {
//$field_value = wordwrap($field_value, $word_wrap_col, "\n", $enable_word_wrap_cut);
//$field_to_display = "<SPAN DIR=rtl><div style=\"text-align: right;\">".$field_value."</div></SPAN>";
$field_to_display = "<SPAN DIR=rtl><div style=\"text-align: right;\">".wordwrap($field_value, $word_wrap_col, "\n", $enable_word_wrap_cut)."</div></SPAN>";
}
else{
$field_to_display = $field_value;
} // end else
break;

using field_value variable in all cases?

 

egurevich

Member
No that didn't work either.
See here. the columns on the right side are as wide as the text in them.

http://www.seforimonline.org/seforimdb/
 

DebbieS

DaDaBIK Guru
How about this ... the other code looks more like it's for plain text ... this one converts new lines to line breaks ...

case "text_right_justified":
if ($display_mode == "results_table") {
$field_to_display = "<SPAN DIR=rtl><div style=\"text-align: right;\">".nl2br(wordwrap($field_value, $word_wrap_col))."</div></SPAN>";
}
else{
$field_to_display = $field_value;
} // end else
break;

 
Top