[jQuery] Pager on click not working
I have a table using the tablesorter / pager and I have a on click
function for each of the table rows it works great on page 1 but once
you go to the secound page on it dosent work I have noticed alot of
posts on this on the internet but no one seems to have an answer can
someone please help me figure this out. here is my code
$(document).ready(function(){
$('#add_new').click(function(){
$.cookie('opp_update', '', { expires: -1 });
window.location='/crm/oppform';
});
$('.edit').click(function(){
$.cookie('opp_update', 'true');
$.cookie('opp_id', $("#opp_id").val());
window.location='/crm/oppform';
});
$('.expand-child').hide();
$('#expand_main').click(function(){
var status = $(this).attr("rel");
if (status != 'minus') {
$('#main_tbl .expand-child').show();
$(this).html('<img src="/images/icon_minus.gif"
height="13px" width="13px">');
$(this).attr("rel", "minus");
}
else {
$('#main_tbl .expand-child').hide();
$(this).html('<img src="/images/icon_plus.gif"
height="13px" width="13px">');
$(this).attr("rel", "plus");
}
});
if ($.cookie('opp_id') != null) {
$('#new_task').show();
$('#close_opp').show();
$('#quote_opp').show();
$("#firstname").val('');
$("#lastname").val('');
$("#company").val('');
$("#countrycode").val('');
$("#phone").val('');
$("#extension").val('');
$("#email").val('');
$("#subject").val('');
$("#details").val('');
var search_field = $('#name_search').val();
var data = '';
$.post("/utils/FoundationSearch/oppsearch?
fields=*&table=opp&where=id = '" + $.cookie('opp_id') + "' and
status='" + $('#status').val() + "' and assigned_contact_id is not
null&bool=F", function(data){
data = JSON.stringify(data);
row_count = data.split("{id:");
var json_array = JSON.parse(data);
if (row_count.length < 1) {
document.getElementById('messages').innerHTML = "<span
style='font-weight:bold; font-color:#FF0000;'>0 Search Results found
with this criteria</span>";
}
else {
if (row_count.length == 1) {
$('#sub_addbtn').hide();
$('#sub_updatebtn').show();
var row_array;
for (var row in json_array) {
row_array = json_array[2].split(",");
}
$.post("/utils/FoundationSearch/gridselect", {
fields: "*, (select (nick_name || ' ' ||
last_name) from contact where id = opp.assigned_by) as by",
table: "opp",
where: "id = " + $.cookie('opp_id') + " and
assigned_contact_id is not null",
orderby: "id asc",
bool: "F"
}, function(json){
json_array = json.split("{");
if (json_array.length - 1 <= 1) {
$('#sub_addbtn').hide();
$('#sub_updatebtn').show();
var my_row_array;
for (var row in json_array) {
my_row_array = JSON.parse(json);
}
var count = 0;
jQuery.each(my_row_array, function(i, val)
{
var phone = '';
var cc = '';
var ext = '';
if (count === 0) {
$("#opp_id").val(val);
}
if (count == 7) {
if(val == 'closed'){
$('#new_task').hide();
$('#close_opp').hide();
$('#quote_opp').hide();
}
}
if (count == 1) {
var Y = val.substring(0, 4);
var M = val.substring(5, 7); //
Jan-Dec=01-12
var D = val.substring(8, 10);
var H = val.substring(11, 13);
var N = val.substring(14, 16);
var S = val.substring(17, 19);
var SS = val.substring(20,
val.length);
DObj = M + '/' + D + '/' + Y + ' '
+ H + ':' + N;
var date = new Date(DObj).format
("MMM dd, yyyy HH:mm ");
$("#submitted").html(date);
}
if (count == 20) {
var Y = val.substring(0, 4);
var M = val.substring(5, 7); // Jan-
Dec=01-12
var D = val.substring(8, 10);
var H = val.substring(11, 13);
var N = val.substring(14, 16);
var S = val.substring(17, 19);
var SS = val.substring(20,
val.length);
DObj = M + '/' + D + '/' + Y + ' ' + H
+ ':' + N + ':' + S;
var date = new Date(DObj).format("MMM
dd, yyyy HH:mm ");
$("#assigned_on").html(date);
}
if (count == 21) {
$("#by").html(val);
}
if (count == 9) {
val = val.replace('/',"");
$("#name").html(val);
}
if (count == 10) {
val = val.replace('/',"");
$("#name").html($("#name").html()
+ " " + val);
}
if (count == 11) {
val = val.replace('/',"");
$('#company_name').html(val);
}
if (count == 12) {
cc += val;
if (cc != 'null') {
$('#phone').html($
('#phone').html() + cc);
}
}
if (count == 13) {
phone += val;
if (phone != 'null') {
$('#phone').html($
('#phone').html() + phone);
}
}
if (count == 14) {
ext += val;
if (ext != 'null') {
$('#phone').html($
('#phone').html() + ext);
}
}
if (count == 15) {
$("#email").html('<a
href="mailto:' + val + '">' + val + '</a>');
}
if (count == 16) {
if(val != null){
val = val.replace('/',"");
$("#small_Subject").html(val.substr(0,
20));
$("#subject").html(val);
}
}
if (count == 17) {
if (val != null) {
val = val.replace('/',"");
$("#details").html(val);
}
}
if (count == 18) {
$("#via").html(val);
}
count = count + 1;
});
}
$.post("/crm/Opps/todo?id=" + $('#opp_id').val
(), function(data){
data = JSON.stringify(data);
json_array = data.split('}{');
var rowcount = 1;
var my_row_array;
var by_name = '';
var todo = '<table width="100%" border="0"
cellpadding="0" cellspacing="0" class="grid tablesorter2"
id="todotable"><thead><tr backgound-color="#eeeeef" style="font-
weight:bold; align:left;text-decoration: underline;"><th
valign="top"></th><th valign="top" align="left" class="sortable
date"><h4><strong>Due Date</strong></h4></th><th valign="top"
align="left" class="sortable text"><h4><strong>Notes</strong></h4></
th><th valign="top" align="left" class="sortable
date"><h4><strong>Created</strong></h4></th><th valign="top"
align="left" class="sortable text"><h4><strong>Type</strong></h4></
th><th valign="top"></th><th valign="top"></th></tr></thead><tbody>';
jQuery.each(json_array, function(i, val){
my_row_array = val.split(',');
var count = 0;
var notes = '';
var due_date = '';
var created = '';
var by = '';
var id = '';
jQuery.each(my_row_array, function(i2,
val2){
if (count === 0) {
id = val2.replace(/\W/g, '');
id = id.replace(/id/g, '');
}
if (val2.indexOf("due_date") > 0)
{
val2 = val2.replace
('due_date', '');
val2 = val2.replace(/\{\|\}\|\
\"\|\\\|\"\|\:\|,/g, '');
var Y = val2.substring(7, 11);
var M = val2.substring(12,
14); // Jan-Dec=01-12
var D = val2.substring(15,
17);
var H = val2.substring(18,
20);
var N = val2.substring(21,
23);
var S = val2.substring(24,
26);
var SS = val2.substring(27,
33)
DObj = M + '/' + D + '/' + Y +
' ' + H + ':' + N + ':' + S;
var date = new Date
(DObj).format("MMM dd, yyyy");
due_date = date;
}
if (val2.indexOf("notes") > 0) {
notes = val2;
notes = notes.replace(/\W"/g, '');
notes = notes.replace
('notes:', '');
}
if (val2.indexOf("create_date") >
0) {
val2 = val2.replace
('create_date', '');
val2 = val2.replace(/\{\|\}\|\
\"\|\\\|\"\|\:\|,/g, '');
var Y = val2.substring(7, 11);
var M = val2.substring(12,
14);
var D = val2.substring(15,
17);
var H = val2.substring(18,
20);
var N = val2.substring(21,
23);
var S = val2.substring(24,
26);
var SS = val2.substring(27,
33)
DObj = M + '/' + D + '/' + Y +
' ' + H + ':' + N + ':' + S;
var date = new Date
(DObj).format("MMM dd, yyyy");
created = date;
}
if (val2.indexOf("create_by") > 0)
{
by = val2;
by = by.replace(/\W"/g, '');
by = by.substring(10,
by.length);
by = by.replace('create_by:',
'');
}
if (val2.indexOf("type") > 0) {
type = val2;
type = type.replace(/\W"/g,
'');
// type = type.substring(10,
type.length);
type = type.replace('type:',
'');
}
count = count + 1;
});
todo += '<tr id="task_1_' + id + '"
valign="top"';
if (rowcount % 2) {
todo += ' style="background:
#FFFFFF;"';
}
else {
todo += ' style="background:
#eeeeef;"';
}
todo += '><td valign="top"
class="collapsabile"><div id="expand_' + id + '" class="expand"
rel="plus"><img src="/images/icon_plus.gif" height="13px"
width="13px"></div></td><td valign="top"><input type="text" id="dd_' +
id + '" size="30%"';
if (rowcount % 2) {
todo += 'style="border-
color:#FFFFFF; background-color:#FFFFFF;"';
}
else {
todo += 'style="border-
color:#eeeeef; background-color:#eeeeef;"';
}
todo += ' value="' + due_date + '"
readonly></td><td valign="top" id="notes_' + id + '"><textarea
rows="1" cols="80" id="txtnotes_' + id + '" ';
if (rowcount % 2) {
todo += 'style="height:18px;
border-color:#FFFFFF; background-color:#FFFFFF;"';
}
else {
todo += 'style="height:18px;
border-color:#eeeeef; background-color:#eeeeef;"';
}
todo += ' wrap="soft" readonly>' +
notes.substring(0, 80) + '</textarea><div id="notes2_' + id + '"
class="hidenotes">' + notes + '</div><div id="notes3_' + id + '"
class="nevershownotes">' + notes + '</div><div id="notes3_' + id + '"
class="nevershownotes">' + notes + '</div><td valign="top">' + created
+ ' </td><td valign="top" id="type_' + id + '">' + type +
'</td>';
todo += '<td valign="top"><div
id="task_phone_' + id + '" class="task_phone"><img src="/images/
Icon_phone.gif" width="13" height="13" /></div></td><td
valign="top"><a href="' + $("div #email a").attr("href") + '"><img
src="/images/email_Icon.gif" width="15" height="13" border=0/></a></
td></tr>';
todo += '<tr class="expand-child"
id="update_row_' + id + '" align="right"><td colspan="5"
valign="top"><span style="align:right"><button id="update_task_' + id
+ '" type="button">Update Task</button><button id="close_task_' + id +
'" type="button">Close Task</button></span></td></tr>';
rowcount = rowcount + 1;
});
todo += "</tbody></table>";
if (data.length <= 2) {
$('#tasks').html('There are currently
no Tasks assigned to the Opp');
}
else {
$('#tasks').html(todo);
$('.nevershownotes').hide()
$('.hidenotes').hide();
$('.expand-child').hide();
$('tr [id^="update_row_"]').hide();
$
(".tablesorter2") /*
* td.collapsible = collapse to the
first table row and show +/-
* td.collapsible_alt = anchor to
order number
*/
.collapsible("td.collapsible", {
collapse: true
}).tablesorter({
// set default sort column
sortList: [[0, 1]],
// don't sort by first column
// headers: {
// 0: {
// sorter: false
// }
//} // set the widgets being used
- zebra stripping
//,
widgets: ['zebra'],
onRenderHeader: function(){
this.wrapInner("<span></
span>");
},
debug: false
});
$('button[id^="update_task_"]').click
(function(){
var id = $(this).attr("id").split
("task_");
var note = $("#txtnotes_" + id[1]).val().replace(/\n/
g,'%0A');
note = $("#txtnotes_" + id[1]).val().replace(/\r/g,'%0D');
$.post("/crm/Opps/updatetodo?id="
+ id[1] + "&due_date=" + $("#dd_" + id[1]).val() + "¬es=" + note,
function(){
updatemesg('Task Updated
Successfully');
todorefresh();
activityrefresh();
$('button
[id^="update_task_"]').blur();
});
});
$('button[id^="close_task_"]').click
(function(){
var id = $(this).attr("id").split
("task_");
$('#task_1_' + id[1]).hide();
$('#update_row_' + id[1]).hide();
$.post("/crm/Opps/closetodo?id=" +
id[1] + "&due_date=" + $("#dd_" + id[1]).val() + "¬es=" + $
("#txtnotes_" + id[1]).val(), function(){
});
$('#messages').html('Task Closed
Successfully');
todorefresh();
activityrefresh();
$('button[id^="close_task_"]').blur
();
});
$('.task_phone').click(function(){
$('#intel').val('Qualified');
$('#phone_form').dialog('open');
$("#phone_form").dialog('option',
'width', 500);
$('#phone_close').hide();
$('#phone_notes').val(' ');
$('#con_close').hide();
$('#continue_header').hide();
$('#continue_task').show();
var id = $(this).attr("id").split
("phone_");
$('#intel').change(function(){
if ($('#intel').val() ==
'close') {
$('#phone_close').show();
}
});
$('#continue_task').click(function
(){
$('#phone_form').dialog
('close');
if ($('#intel').val() ==
'close') {
if ($('#phone_close').val() == 0) {
$('#messages').html('<span style="color:#FF0000;">You Must
Select a Close Reason</span>');
}
else {
var taskid = id;
$.post("/crm/opps/con_task?close_reason=" + $
('#phone_close').val() + "&intel=" + $('#intel').val() + "&opp_id=" + $
('#opp_id').val() + "&task_id=" + taskid[1] + "¬es=" + $
('#phone_notes').val(), function(){
});
$('#messages').html('Opportunity Closed Successfully');
window.location.reload();
}
}
else {
var taskid = id;
var notes = $('#notes3_' + taskid[1]).html() + $
('#phone_notes').val();
$.post("/crm/opps/con_task?intel=" + $('#intel').val() +
"&opp_id=" + $('#opp_id').val() + "&task_id=" + taskid[1] + "¬es="
+ notes, function(){
});
todorefresh();
activityrefresh();
}
});
});
$('.expand').click(function(){
var id = $(this).attr("id").split
("_");
var status = $(this).attr("rel");
var prev_html = "";
var details_html = "";
if (status != 'minus') {
prev_html = $('#txtnotes_' + id
[1]).val();
$('#txtnotes_' + id[1]).val($
('#notes2_' + id[1]).html());
$('#txtnotes_' + id[1]).attr
("rows", "10");
$('#txtnotes_' + id[1]).attr
("cols", "80");
$('#txtnotes_' + id[1]).css
('height', '130px');
$('#txtnotes_' + id[1]).css
('border-color', '#FFFFFF');
$('#notes2_' + id[1]).html
(prev_html);
$('#txtnotes_' + id
[1]).removeAttr('readonly');
$('#dd_' + id[1]).removeAttr
('readonly');
$('#update_row_' + id[1]).show
();
$(this).html('<img src="/
images/icon_minus.gif" height="13px" width="13px">');
$(this).attr("rel", "minus");
}
else {
prev_html = $('#txtnotes_' + id
[1]).val();
$('#notes2_' + id[1]).html($
('#txtnotes_' + id[1]).val());
$('#txtnotes_' + id[1]).attr
("rows", "1");
$('#txtnotes_' + id[1]).attr
("cols", "80");
$('#txtnotes_' + id[1]).css
('height', '18px');
$('#txtnotes_' + id[1]).val
(prev_html.substring(0, 80));
$('#update_row_' + id[1]).hide
();
$(this).html('<img src="/
images/icon_plus.gif" height="13px" width="13px">');
$(this).attr("rel", "plus");
}
});
}
});
$.post("/crm/Opps/activity?id=" + $
('#opp_id').val() + "&days=" + $("input[@name='radio']:checked").val
(), function(d2){
data = JSON.stringify(d2);
json_array = data.split('}{');
var rowcount = 1;
var my_row_array;
var by_name = '';
var due_date = '';
var activity = '<table width="100%"
border="0" cellpadding="0" cellspacing="0" class="grid tablesorter3"
id="acti