Mask - phone number
Mask - phone number
Good afternoon!
I can't implement the "editor.mask" plugin»:
https://editor.datatables.net/plug-ins/field-type/editor.mask
You can see it here:
http://www.a0250268.xsph.ru/index.php/crm-kandidat
JS
(function($){
$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
ajax: '/abc_crm/dt/my/crm_kandidat/crm_kandidat.php',
table: '#crm_kandidat',
fields: [
{
label: "tel:",
name: "crm_kandidat.tel",
type: "mask",
mask: "+7(000)-000-00-00",
placeholder: "+7(ххх)-ххх-хх-хх"
}
],
// --- Для редактирования внутри ячейки ---
formOptions: {
inline: {
onBlur: 'submit'
}
}
} );
var table = $('#crm_kandidat').DataTable( {
// dom: 'Bfrtip', // Убираем кнопки
// language: {
// url: '/abc_crm/dt/lang/russian.json' // Русификация
// },
language: {
url: '../../lang/russian.json'
},
ajax: '/abc_crm/dt/my/crm_kandidat/crm_kandidat.php',
columns: [
{
"data": "vybory_user_card.deputy"
},
{
"data": "crm_kandidat.tel"
}
],
// --- Для редактирования внутри ячейки ---
keys: {
columns: ':not(:first-child)',
keys: [ 9 ],
editor: editor,
editOnFocus: true
},
// ------------------------------------------
select: true,
lengthChange: false,
buttons: [
{ extend: 'create', editor: editor },
{ extend: 'edit', editor: editor },
{ extend: 'remove', editor: editor }
]
} );
} );
}(jQuery));
This question has accepted answers - jump to:
Answers
It works like this for me:
editor.on('onOpen', function () {
$('#DTE_Field_installers-Installers_phone').mask('+7(999)999-99-99');
});
On top of @Alexandr45 's suggestion, also see this example here: http://live.datatables.net/gefesida/1/edit
Colin
I appreciate your help, but an example http://live.datatables.net/gefesida/1/edit it doesn't work for me!
Maybe I'm doing something wrong? I took the HTML and JS codes from this example – just one to one.
I got it like this.
I'm at a loss!
You are loading two versions of jQuery mask.
However, I see that the working example is doing the same thing. So this isn't any help.
Are you certain that the rest of your code matches the example?
It doesn't look like the table is being initialised in your code. You would need to do that to get the Editor code enabled to edit the table,
Colin
Thank you so much, I really forgot to connect Edit
I'm sorry to bother you. In the example: http://live.datatables.net/gefesida/1/edit it shows how the mask is applied when entering a value in the field. And how to put a mask on the output of values in the table? In the example, the data is fixed with separators. I.e., for example, in the database I have the value "9090570341", and in the table "+7(909)-057-03-41" My example: http://www.a0250268.xsph.ru/
I'm not clear what the question is, sorry. Are you asking for the formatting to also be applied to the database?
Colin
Sorry. In the database - not formatted:
https://prnt.sc/16kjy57
I would like it to be output in formatted form for the user.
Understood: "render"
That's right - you would use
columns.render
to get it displayed in the table.Colin