Skip to content

Instantly share code, notes, and snippets.

@annuman97
annuman97 / displayTableBasedonUserLocation.js
Last active March 26, 2022 09:33
Display Table based on user Location
/*Display Table based on User Location*/
$(document).ready(function(){
fetch('https://api.ipregistry.co/?key=tryout')
.then(function (response) {
return response.json();
})
.then(function (payload) {
if(payload.location.city == 'Dhaka'){
$('#footable_parent_660').css('display', 'none');
}else{
/*Count rows of the table (it will work if filter is applied)*/
function runAll(){
var rowCount = FooTable.get('#footable_534').toJSON().rows.length;
var fixCount = FooTable.get('#footable_534').toJSON().rows.length;
var $countWrapper = $table.parent();
$countWrapper.prepend('<div class="remove">Total <span>' + rowCount + "</span> data found</p>");
$table.on('postdraw.ft.table', function(e, ft) {
jQuery('.remove').remove();
var rowsCount = ft.rows.array.length;
$countWrapper.find('.table_info_count .current_count').html(rowsCount + " of " + fixCount);
/*replace an attribute based on site language */
let siteLan = document.documentElement.lang;
let findAreaLabel = document.querySelector('.btn-primary').getAttribute("aria-label");
if(siteLan == "zh-TW")
{
document.querySelector('.btn-primary').removeAttribute("aria-label");
document.querySelector('.btn-primary').setAttribute("aria-label", "搜尋");
}else if(siteLan == "en")
/*Ninja Table hide some rows and display them on click at first cell*/
jQuery('tbody tr:nth-child(n+2):nth-child(-n+4)').hide();
jQuery('tbody tr:nth-child(n+6):nth-child(-n+8)').hide();
$(document).ready(function() {
jQuery('.footable > tbody > tr:first-child > td:first-child').click(function() {
jQuery('tbody tr:nth-child(n+2):nth-child(-n+4)').toggle();
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
var btnn = document.querySelector('.footable_parent');
let btn = document.createElement("button");
btn.classList.add('mybtn');
btn.innerHTML = "DISPLAY FILTERS";
btnn.prepend(btn);
$('tr.footable-filtering').hide();
var btnn = document.querySelector('.footable-filtering');
let btn = document.createElement("button");
btn.classList.add('mybtn');
btn.innerHTML = "DISPLAY TABLE BODY";
btnn.append(btn);
$('.footable tbody').hide();
document.querySelector('button.mybtn').addEventListener('click', function(){
add_filter('fluentform_validate_input_item_input_email', function($errorMessage, $field, $formData, $fields, $form) {
$target_id = [59,60];
$target_form_id = 0;
foreach($target_id as $id){
if($form->id == $id){
@annuman97
annuman97 / ninjaTablesNumbertoStar.php
Created May 4, 2023 06:54
Replace Numbers to Star in ninja table column
add_filter('ninja_tables_get_public_data', function ($data, $tableId) {
if ($tableId == 3156) {
for($i = 0; $i < count($data); $i++){
$val = $data[$i]['player_ranking'];
$arr = [];
$icon = '[nt_icon icon="star" color="orange"]';
for($j = 1; $j<= $val; $j++){
array_push($arr, $icon);
@annuman97
annuman97 / gist:c7f7e49068f52abfbe7693e2f79cf6fe
Created July 24, 2023 09:31
Randomize/shuffle the table rows each time after refresh the page
(function($){
//Shuffle all rows, while keeping the first column
//Requires: Shuffle
$.fn.shuffleRows = function(){
return this.each(function(){
var main = $(/table/i.test(this.tagName) ? this.tBodies[0] : this);
var firstElem = [], counter=0;
main.children().each(function(){
firstElem.push(this.firstChild);
});
@annuman97
annuman97 / ninjaTablesAutoSerialNumberforMultipleTables.php
Last active May 7, 2024 11:26
Auto Serial Number to multiple ninja tables
add_filter('ninja_table_rendering_table_vars',function($table_vars, $table_id, $tableArray){
$target_id = [2607,2608];//add all tables ID here
$tableId = 0;
foreach($target_id as $id){
if($table_id == $id){
$tableId = $id;
}
}