You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Plugins/dataRender/numberTo.js

90 lines
2.4 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/*! © SpryMedia Ltd, Alireza Mohammadi Doost - datatables.net/license */
(function( factory ){
if ( typeof define === 'function' && define.amd ) {
// AMD
define( ['jquery', 'datatables.net'], function ( $ ) {
return factory( $, window, document );
} );
}
else if ( typeof exports === 'object' ) {
// CommonJS
module.exports = function (root, $) {
if ( ! root ) {
// CommonJS environments without a window global must pass a
// root. This will give an error otherwise
root = window;
}
if ( ! $ ) {
$ = typeof window !== 'undefined' ? // jQuery's factory checks for a global window
require('jquery') :
require('jquery')( root );
}
if ( ! $.fn.dataTable ) {
require('datatables.net')(root, $);
}
return factory( $, root, root.document );
};
}
else {
// Browser
factory( jQuery, window, document );
}
}(function( $, window, document, undefined ) {
'use strict';
var DataTable = $.fn.dataTable;
/**
* Convert numbers to farsi, english, arabic.
* تبدیل عداد به فارسی, انگلیسی, عربی
*
* @name convertTo
* @summary convert numbers to farsi, english, arabic.
* @author Alireza Mohammadi Doost
*
* @example
* $('#example').DataTable( {
* columnDefs: [ {
* targets: 2,
* render: DataTable.render.numberTo('fa')
* } ]
* } );
*/
DataTable.render.numberTo = function (to = 'fa') {
let result = null;
const faNumbers = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
const enNumbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
const arNumbers = ['۰', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'];
return function (d, type, row) {
if (type !== 'display') {
return d;
}
if (!d && to === 'fa') {
return 'مقدار ورودی صحیح نمی‌باشد.';
}
else if (!d) {
return 'numbers is empty.';
}
switch (to) {
case 'fa':
result = d.toString().replace(/\d/g, x => faNumbers[x]);
break;
case 'en':
result = d.toString().replace(/\d/g, x => enNumbers[x]);
break;
case 'ar':
result = d.toString().replace(/\d/g, x => arNumbers[x]);
break;
}
return result;
};
};
return DataTable;
}));