⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Print output doesn't match with view in html



0zz1s
  • profile picture
  • Member

Posted 06 July 2013 - 18:38 PM

How to make print function uses the view (html page) css ? By default, the print output is left-to-right, but i want to make some columns align center and the others align right.
I already searched in this forum and still didn't get the answer. Anybody have idea?

goFrendiAsgard
  • profile picture
  • Member

Posted 07 July 2013 - 00:50 AM

td:nth-child(2) div
{
text-align:right!important;
}

That one will make the second column to be right-aligned


0zz1s
  • profile picture
  • Member

Posted 07 July 2013 - 06:41 AM

Where should i place the code? I tried to make a new css file and place it in the same html page but it didn't work.

0zz1s
  • profile picture
  • Member

Posted 07 July 2013 - 06:49 AM

Your answer is right frenAsgard, but that only works for views in html page. It doesn't work for print preview after button print clicked.
How to make the print preview use our custom css?

goFrendiAsgard
  • profile picture
  • Member

Posted 07 July 2013 - 12:20 PM

Unfortunately there is no way to modify print page without extending or editing groceryCRUD library itself.

 

The quick and dirty way is to find _print_webpage function in /application/libraries/grocery_CRUD.php

The function contains this:

protected function _print_webpage($data)
	{
		$string_to_print = "<meta charset=\"utf-8\" /><style type=\"text/css\" >
		#print-table{ color: #000; background: #fff; font-family: Verdana,Tahoma,Helvetica,sans-serif; font-size: 13px;}
		#print-table table tr td, #print-table table tr th{ border: 1px solid black; border-bottom: none; border-right: none; padding: 4px 8px 4px 4px}
		#print-table table{ border-bottom: 1px solid black; border-right: 1px solid black}
		#print-table table tr th{text-align: left;background: #ddd}
		#print-table table tr:nth-child(odd){background: #eee}
		</style>";
		$string_to_print .= "<div id='print-table'>";

		$string_to_print .= '<table width="100%" cellpadding="0" cellspacing="0" ><tr>';
		foreach($data->columns as $column){
			$string_to_print .= "<th>".$column->display_as."</th>";
		}
		$string_to_print .= "</tr>";

		foreach($data->list as $num_row => $row){
			$string_to_print .= "<tr>";
			foreach($data->columns as $column){
				$string_to_print .= "<td>".$this->_trim_print_string($row->{$column->field_name})."</td>";
			}
			$string_to_print .= "</tr>";
		}

		$string_to_print .= "</table></div>";

		echo $string_to_print;
		die();
	}

Add your css there.

WARNING: that gonna applied globally