⚠ 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

How to Link with Title & Seen/Unseen record?



likhon3k
  • profile picture
  • Member

Posted 18 November 2014 - 15:00 PM

Hello All,

How are you everybody.

 

I have two query, I search but failed to get the solution.

 

one is, I want to give a link on title of a record if the table field is

 

Table: Article

 

id

title

body

status

 

>> we can add view/edit/delete button/link. but I want to give a linke on title field.

 

 

second question is: I want to read/unread data or seen/unseen data. if any any new data record will be inserted then the title will be bold font, if i see it then it will be normal font.

 

any one can give me the solution please?


likhon3k
  • profile picture
  • Member

Posted 18 November 2014 - 15:05 PM

sorry for repeat . My internet connection was disconnected when i post the article. I thought posting was not successful and then i refreshed the page. please remove rest  post which is same as it.


Amit Shah
  • profile picture
  • Member

Posted 18 November 2014 - 18:36 PM

Well .. 1st for linking - technically it can be done in with 2 ways around - 1 is with callback.. where u give hyperlink to all the elements .. to the desired link...

2 - OR u can write a javascript that will manipulate the list for the same...

u have to use the following changes in the library / template as mentioned below.

/topic/2260-do-javascript-function-after-ajax-list-finished/

 

 

As for the read / unread .. its the same stuff.. either u can have a callback.. and format the output accordingly .. or u can simple write a javascript that will alter the values based on the row - condition. Choice is yours..

JS - will be cleaner coding but tough...

Callback will be nastier but fruitfull..


likhon3k
  • profile picture
  • Member

Posted 19 November 2014 - 18:18 PM

Well .. 1st for linking - technically it can be done in with 2 ways around - 1 is with callback.. where u give hyperlink to all the elements .. to the desired link...

2 - OR u can write a javascript that will manipulate the list for the same...

u have to use the following changes in the library / template as mentioned below.

/topic/2260-do-javascript-function-after-ajax-list-finished/

 

 

As for the read / unread .. its the same stuff.. either u can have a callback.. and format the output accordingly .. or u can simple write a javascript that will alter the values based on the row - condition. Choice is yours..

JS - will be cleaner coding but tough...

Callback will be nastier but fruitfull..

 

thanks for your reply.

 

can you give me a hints or example for call back function for both problems?


Amit Shah
  • profile picture
  • Member

Posted 20 November 2014 - 01:57 AM

Well my friend.. here there will be technically callback for every column.

callback consists of 2 params - $value, $row

 

for the value - based on the condition of the field from the $row, for the value what you could do is return a formatted / non-formatted a href link attached to the same.

 

other way around - which is still better - dont give ahref for all ....

just make a slight change in the view (list.php of the gc templete / theme u use) - where it starts with the printing the row out..

<?php foreach($list as $num_row => $row){ ?>
		<tr <?php if($num_row % 2 == 1){?>class="erow"<?php }?> data_id="<?php echo $row->$primary_key ?>">

here.. what we added is data_id="<?php echo $row->$primary_key ?>"

this makes each row havea data_id...

 

now what you can do is write a script in js ..

$("tr").click(function(event) {
    window.location.href = somebaseurl + $(this).attr("data_id");   //generate the url now based on the id.
});

this .. u can attach to the crud using set_js function

 

as for formatting - u can alter the library as guided above ... and u can create a function

function formatRows() {
	var myValue = $(this).find('td:eq(4)').text();    //assuming the value for comparision is alreeady in the column at the 4th element 
	if(myValue == 'formatable') {
		$('#flex1 tbody tr').each(function(i) {
			//format the column - attach css like bold / strong to the text  .... or some color to the text
		});
	}
}

now the same can be set in the above give js ... (which we added for the link) and ...add a callback...

$crud->post_ajax_callbacks('formatRows()');

 

thats it - its all set with the code without callback...

but mind it - this is technically only possible if we have the value for comparision present in the row itself.