Trigger automatically row update each x time

QuestionsTrigger automatically row update each x time
C3media asked 6 years ago

Hello,

I have a grid with two columns: DEPARTURE – TIME_CONSUMED

Then i would like after insert row, to update time_consumed column based in real time.

It's possible using trigger?

Thank you!

2 Answers
Abu Ghufran answered 6 years ago

You can write custom php code to update time_consumed in on_insert function callback OR on_after_insert.
Refer http://www.phpgrid.org/docs/#Grid_Events

C3media answered 6 years ago

Hello Abu,

I have tried with this basic funtion, it's a timer:

<script>
// Set the date we're counting down to
var countDownDate = new Date("Jan 5, 2018 15:37:25").getTime();

// Update the count down every 1 second
var x = setInterval(function() {

// Get todays date and time
var now = new Date().getTime();

// Find the distance between now an the count down date
var distance = countDownDate – now;

// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);

// Display the result in the element with id="demo"
document.getElementById("demo").innerHTML = hours + "h "
+ minutes + "m " + seconds + "s ";

// If the count down is finished, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "EXPIRED";
}
}, 1000);

</script>

Then in grid col:

# Custom made column to show extra buttons, must have default value as it's not db driven
$col = array();
$col["title"] = "Timer";
$col["name"] = "more_icons";
$col["fixed"] = true;
$col["width"] = "85";
$col["align"] = "center";
$col["search"] = false;
$col["sortable"] = false;
# no new line in this html, only space. otherwise it may break ui of grid
$buttons_html .= '<p id="demo"></p>';
$col["default"] = $buttons_html;
$sales[] = $col;

This is working in first row, other rows are empty; otherwise the countDownDate Var is based in a Date of Row so:

var rowid = jQuery("#list1").jqGrid("getGridParam","selrow");

var row = $("#list1").getRowData(rowid);

var date= row["date"];

Thank you by your help!

Your Answer

1 + 6 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 3 / 5. Vote count: 1

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?