Filter by year with buton in TV

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
nrobert
Posts: 5
Joined: 2020-09-08 13:08
Location: Blackpool, England
Contact:

Filter by year with buton in TV

Post by nrobert » 2022-07-14 07:58

Hi All,

Hope somebody can help ?

I am trying to add buttons to the Table Veiw to allow users to only see "This Year" or "Last Year" and then only "Confirmed Orders" for that filtered year, I have managed to add new buttons however the code attached to them does not work. ??

The code I have used in "invoices.tv.js" is as follows:

/* end of mass_update code */

jQuery(function(){
jQuery('.clearfix').after('<button class="btn btn-success btn-lg"" type="button" id="filter-button"><i class="glyphicon glyphicon glyphicon-print"></i> This Year</button>');
jQuery('button[id=filter-button]').click(function(){
window.location = 'invoices_view.php?SortField=&SortDirection=&FilterAnd%5B1%5D=and&FilterField%5B1%5D=11&FilterOperator%5B1%5D=greater-than-or-equal-to&FilterValue%5B1%5D=01%2F01%2F2022&FilterAnd%5B2%5D=and&FilterField%5B2%5D=11&FilterOperator%5B2%5D=less-than-or-equal-to&FilterValue%5B2%5D=31%2F12%2F2022';
});
});

jQuery(function(){
jQuery('.clearfix').after('<button class="btn btn-success btn-lg"" type="button" id="filter-button"><i class="glyphicon glyphicon glyphicon-print"></i> Last Year</button>');
jQuery('button[id=filter-button]').click(function(){
window.location = 'invoices_view.php?SortField=&SortDirection=&FilterAnd%5B1%5D=and&FilterField%5B1%5D=11&FilterOperator%5B1%5D=greater-than-or-equal-to&FilterValue%5B1%5D=01%2F01%2F2021&FilterAnd%5B2%5D=and&FilterField%5B2%5D=11&FilterOperator%5B2%5D=less-than-or-equal-to&FilterValue%5B2%5D=31%2F12%2F2021';
});
});

jQuery(function(){
jQuery('.clearfix').after('<button class="btn btn-success btn-lg"" type="button" id="filter-button"><i class="glyphicon glyphicon glyphicon-print"></i> Confirmed</button>');
jQuery('button[id=filter-button]').click(function(){
window.location = 'invoices_view.php?SortField=&SortDirection=&FilterAnd%5B1%5D=and&FilterField%5B1%5D=11&FilterOperator%5B1%5D=greater-than-or-equal-to&FilterValue%5B1%5D=01%2F01%2F2021&FilterAnd%5B2%5D=and&FilterField%5B2%5D=11&FilterOperator%5B2%5D=less-than-or-equal-to&FilterValue%5B2%5D=31%2F12%2F2021';
});
});


I have a code written in links-navmenu.php that works OK for current year but have to go to main menu to use which is not ideal ? this is the menu code:
/* This Year Invoices links */
$navLinks[] = array(
'url' => 'invoices_view.php?SortField=2+asc%2C3&SortDirection=asc&FilterAnd%5B1%5D=and&FilterField%5B1%5D=11&FilterOperator%5B1%5D=greater-than-or-equal-to&FilterValue%5B1%5D=01%2F04%2F' . date('Y') . '&FilterAnd%5B2%5D=and&FilterField%5B2%5D=11&FilterOperator%5B2%5D=less-than-or-equal-to&&FilterValue%5B2%5D=31%2F12%2F' . date('Y'),
'icon' => 'resources/table_icons/table_go.png', // optional icon to use with the link
'title' => 'This Years Orders',
'groups' => array('*'), // groups allowed to see this link, use '*' if you want to show the link to all groups
'table_group' => '1' // optional name of the table group you wish to add the link to. If the table group name contains non-Latin characters, you should convert them to html entities.

);

Is there any way I can use this code in the button on the TV currently, if I paste the "filter" part of the code into the invoice_veiw line the buttons disapear ???

hoping someone can point me in right direction ?
Attachments
Appg TV.PNG
Table view
Appg TV.PNG (137 KiB) Viewed 928 times

angus
Veteran Member
Posts: 128
Joined: 2020-05-28 22:27

Re: Filter by year with buton in TV

Post by angus » 2022-08-30 19:57

probably a bit too late but if you create one of the magic files in hooks/yourtablename-tv.js
and then add this. You will need to update this based on years (I am using this month) and also references for your table

Code: Select all

//Records This Month
function padTo2Digits(num) {
  return num.toString().padStart(2, '0');
}

function formatDate(date = new Date()) {
  return [
	date.getFullYear(),
	padTo2Digits(date.getMonth() + 1),       
  ].join('/');
}


$j(function() {
var thisMonth = formatDate();
var filter1 = {
		'FilterAnd[1]': 'and',
        'FilterField[1]': 54,  // change this to the actual index of your data field
        'FilterOperator[1]': 'like',
        'FilterValue[1]': thisMonth		
	
};


// building the filter url ... change tablename to the actual table name
var url = 'xxxxxxxxxxxxxxxxxxxx.php?SortField=7&SortDirection=desc&' + $j.param(filter1); // change the field to your field number

// finally, insert the filter button
$j('<a class="btn btn-sm btn-warning" href="' + url + '">This Month</a>').appendTo('#top_buttons');
})
AppGini 22.13

Post Reply