$(document).ready(function() { $.fn.dataTable.ext.order['sortMln'] = function ( settings, col ) { return this.api().column( col, {order:'index'} ).nodes().map( function ( td ) { return 1*$(td).text().replace(' mln.', ''); } ); }; $.fn.dataTable.ext.order['sortCountryFlag'] = function ( settings, col ) { return this.api().column( col, {order:'index'} ).nodes().map( function ( td ) { return $('i', td).attr('title'); } ); }; $.fn.dataTable.ext.order['sortMostPopular'] = function ( settings, col ) { return this.api().column( col, {order:'index'} ).nodes().map( function ( td ) { return 1*$(td).text().substr(0,$(td).text().indexOf("x")-1); } ); }; }); var countries = {"214":{"id":"214","country":"England","countryCode":"EN","countryTr":"Inghilterra"},"215":{"id":"215","country":"Scotland","countryCode":"SF","countryTr":"Scozia"},"51":{"id":"51","country":"Australia","countryCode":"AU","countryTr":"Australia"},"216":{"id":"216","country":"Wales","countryCode":"WL","countryTr":"Galles"},"61":{"id":"61","country":"Netherlands","countryCode":"NL","countryTr":"Olanda"},"217":{"id":"217","country":"Northern Ireland","countryCode":"NIE","countryTr":"Irlanda del Nord"},"36":{"id":"36","country":"Canada","countryCode":"CA","countryTr":"Canada"},"93":{"id":"93","country":"Austria","countryCode":"AT","countryTr":"Austria"},"14":{"id":"14","country":"Germany","countryCode":"DE","countryTr":"Germania"},"28":{"id":"28","country":"Spain","countryCode":"ES","countryTr":"Spagna"},"118":{"id":"118","country":"Ireland","countryCode":"IE","countryTr":"Irlanda"},"3":{"id":"3","country":"United States","countryCode":"US","countryTr":"Stati Uniti"},"76":{"id":"76","country":"Belgium","countryCode":"BE","countryTr":"Belgio"},"88":{"id":"88","country":"Sweden","countryCode":"SE","countryTr":"Svezia"},"218":{"id":"218","country":"Gibraltar","countryCode":"GI","countryTr":"Gibraltar"},"74":{"id":"74","country":"Greece","countryCode":"GR","countryTr":"Grecia"},"33":{"id":"33","country":"Poland","countryCode":"PL","countryTr":"Polonia"},"2":{"id":"2","country":"India","countryCode":"IN","countryTr":"India"},"26":{"id":"26","country":"South Africa","countryCode":"ZA","countryTr":"Sud Africa"},"109":{"id":"109","country":"Denmark","countryCode":"DK","countryTr":"Danimarca"},"112":{"id":"112","country":"Finland","countryCode":"FI","countryTr":"Finlandia"},"80":{"id":"80","country":"Hungary","countryCode":"HU","countryTr":"Ungheria"},"120":{"id":"120","country":"Croatia","countryCode":"HR","countryTr":"Croazia"},"94":{"id":"94","country":"Swiss","countryCode":"CH","countryTr":"Svizzera"},"117":{"id":"117","country":"Norway","countryCode":"NO","countryTr":"Norvegia"},"23":{"id":"23","country":"Italy","countryCode":"IT","countryTr":"Italia"},"145":{"id":"145","country":"Slovenia","countryCode":"SI","countryTr":"Slovenia"},"116":{"id":"116","country":"Singapore","countryCode":"SG","countryTr":"Singapore"},"1":{"id":"1","country":"China","countryCode":"CN","countryTr":"Cina"},"98":{"id":"98","country":"Hong Kong","countryCode":"HK","countryTr":"Hong Kong"},"10":{"id":"10","country":"Japan","countryCode":"JP","countryTr":"Giappone"},"12":{"id":"12","country":"Philippines","countryCode":"PH","countryTr":"Filippine"},"124":{"id":"124","country":"New Zealand","countryCode":"NZ","countryTr":"Nuova Zelanda"},"78":{"id":"78","country":"Czech Republic","countryCode":"CZ","countryTr":"Repubblica Ceca"},"142":{"id":"142","country":"Latvia","countryCode":"LV","countryTr":"Lettonia"},"43":{"id":"43","country":"Malaysia","countryCode":"MY","countryTr":"Malesia"},"19":{"id":"19","country":"France","countryCode":"FR","countryTr":"Francia"},"9":{"id":"9","country":"Russia","countryCode":"RU","countryTr":"Russia"},"20":{"id":"20","country":"Thailand","countryCode":"TH","countryTr":"Tailandia"},"132":{"id":"132","country":"Lithuania","countryCode":"LT","countryTr":"Lituania"},"17":{"id":"17","country":"Turkey","countryCode":"TR","countryTr":"Turchia"},"173":{"id":"173","country":"Brunei","countryCode":"BN","countryTr":"Brunei"},"5":{"id":"5","country":"Brasil","countryCode":"BR","countryTr":"Brasile"},"77":{"id":"77","country":"Portugal","countryCode":"PT","countryTr":"Portogallo"},"81":{"id":"81","country":"Serbia","countryCode":"RS","countryTr":"Serbia"},"52":{"id":"52","country":"Romania","countryCode":"RO","countryTr":"Romania"},"175":{"id":"175","country":"Iceland","countryCode":"IS","countryTr":"Islanda"},"22":{"id":"22","country":"United Kingdom","countryCode":"GB","countryTr":"Regno Unito"},"27":{"id":"27","country":"Ukraine","countryCode":"UA","countryTr":"Ucraina"},"160":{"id":"160","country":"Bahrain","countryCode":"BH","countryTr":"Bahrein"},"161":{"id":"161","country":"Guyana","countryCode":"GY","countryTr":"Guyana"}}; var teams = {"0":{"id":0,"name":""},"152":{"id":"152","name":"BDO","nameTranslated":"BDO"},"153":{"id":"153","name":"PDC","nameTranslated":"PDC"}}; var sportsmen = [{"id":"4932","tem":"153","ctr":"61","nam":"Gerwen, Michael van","namorig":"Gerwen, Michael van","cat":"","pri":"10 mln.","rat":0,"mw":"M","link":"Gerwen, Michael van<\/a>","confirmed_b":1},{"id":"10058","tem":"153","ctr":"216","nam":"Price, Gerwyn ","namorig":"Price, Gerwyn ","cat":"","pri":"8,1 mln.","rat":0,"mw":"M","link":"Price, Gerwyn <\/a>","confirmed_b":1},{"id":"4955","tem":"153","ctr":"214","nam":"Smith, Michael ","namorig":"Smith, Michael ","cat":"","pri":"7,7 mln.","rat":0,"mw":"M","link":"Smith, Michael <\/a>","confirmed_b":1},{"id":"15735","tem":"153","ctr":"214","nam":"Cross, Rob ","namorig":"Cross, Rob ","cat":"","pri":"7,5 mln.","rat":0,"mw":"M","link":"Cross, Rob <\/a>","confirmed_b":1},{"id":"8297","tem":"153","ctr":"214","nam":"Durrant, Glen ","namorig":"Durrant, Glen ","cat":"","pri":"7,2 mln.","rat":0,"mw":"M","link":"Durrant, Glen <\/a>","confirmed_b":1},{"id":"4897","tem":"153","ctr":"214","nam":"Wade, James ","namorig":"Wade, James ","cat":"","pri":"7 mln.","rat":0,"mw":"M","link":"Wade, James <\/a>","confirmed_b":1},{"id":"4925","tem":"153","ctr":"215","nam":"Wright, Peter ","namorig":"Wright, Peter ","cat":"","pri":"6,8 mln.","rat":0,"mw":"M","link":"Wright, Peter <\/a>","confirmed_b":1},{"id":"6803","tem":"153","ctr":"217","nam":"Gurney, Daryl ","namorig":"Gurney, Daryl ","cat":"","pri":"6,7 mln.","rat":0,"mw":"M","link":"Gurney, Daryl <\/a>","confirmed_b":1},{"id":"4902","tem":"153","ctr":"61","nam":"Barneveld, Raymond van","namorig":"Barneveld, Raymond van","cat":"","pri":"5,9 mln.","rat":0,"mw":"M","link":"Barneveld, Raymond van<\/a>","confirmed_b":1},{"id":"4943","tem":"153","ctr":"93","nam":"Suljovic, Mensur ","namorig":"Suljovic, Mensur ","cat":"","pri":"4,5 mln.","rat":0,"mw":"M","link":"Suljovic, Mensur <\/a>","confirmed_b":1}]; var sportsmenTeams = []; var showTeams = 0; //*********************** //SPORTSMEN TABLE HEADERS //*********************** var headersTableSportsmen = [ { 'sTitle': 'No.' }, { 'sTitle': 'Gruppo' , 'bSearchable': false, 'bVisible': false }, { 'sTitle': 'Nazione', 'sSortDataType': 'sortCountryFlag', sType : "text" }, { 'sTitle': 'Giocatore freccette'}, { 'sTitle': 'Valore', 'sSortDataType': 'sortMln', 'sType': 'numeric' }, { 'sTitle': 'Squadra' , 'bSearchable': false, 'bVisible': false }, { 'sTitle': 'M/F' , 'bSearchable': false, 'bVisible': false } ]; //*********************** //TEAMS TABLE HEADERS //*********************** var headersTableTeams = [ {'sTitle': 'No.'}, {'sTitle': '' , 'bSearchable': false, 'bVisible': false }, {'sTitle': 'Nazione' , 'sSortDataType': 'sortCountryFlag', sType : 'text' }, { 'sTitle': ''}, { 'sTitle': 'Valore', 'sSortDataType': 'sortMln', 'sType': 'numeric' } ]; //*********************** //SPORTSMEN TABLE CONTENT //*********************** var contentTableSportsmen = []; $.each(sportsmen, function(k, v) { contentTableSportsmen.push([ k + 1, v['cat'], getFlag(v['ctr']), v['link'], v['pri'], isset(teams[v['tem']])? teams[v['tem']]['name']:'', v['mw'] ]); }); //*********************** //TEAMS TABLE CONTENT //*********************** var contentTableTeams = []; $.each(sportsmenTeams, function(k, v) { contentTableTeams.push([ k + 1, getFlag(v['ctr']), v['nam'], v['pri'] ]); }); function isset (va) { return typeof va != 'undefined'; } $(document).ready(function() { $.fn.dataTable.ext.order['sortMln'] = function (settings, col) { return this.api().column(col, {order: 'index'}).nodes().map(function (td) { return parseFloat($(td).text().replace(' mln.', '').replace(',', '.')); } ); }; if (sportsmen.length) { var sportsmenTable = $('#tblSportsmen').dataTable( { "bPaginate": false, "bFilter": true, "bInfo": false, "bAutoWidth": true, "aoColumns" : headersTableSportsmen, "aaData": contentTableSportsmen, "bAutoWidth": false } ); } if (sportsmenTeams.length) { var sportsmenTeamsTable = $('#tblTeams').dataTable( { "bPaginate": false, "bFilter": true, "bInfo": false, "bAutoWidth": true, "aoColumns" : headersTableTeams, "aaData": contentTableTeams, "bAutoWidth": false } ); $('#teamsOverview').show(); } } ); function getFlag(id, margin) { if (!id || typeof countries[id] === "undefined" ) return ""; if (typeof margin == 'undefined') margin = true; return ""; }