Dynamically change colvis of datatables
Dynamically change colvis of datatables
Hello I have to recover one or more value in select mutiple ; and dynamically display in colvis of datatables .
e.g. I have a list of customers in multiple select and each client has its own information , such CUST1_ and CUST2_ .
CUST1_ contains ( infoA , infoB ) ; CUST2_ contains ( infoA , infoB ) ; and I want to dynamically change the content of colvis ;
eg I click CUST1_ in the select mutiple ; must colvis found only CUST1_infoA and CUST1_infoB ; and if I click on the select mutiple CUST2_ ; must colvis found only CUST2_infoA and CUST2_infoB ; and if I click CUST1_ and CUST2_ in multiple select ; must colvis displays CUST1_infoA , CUST1_infoB , CUST2_infoA , CUST2_infoB and so on
Here is my code.
recovery of data in the multiple select:
$('#data_client').change(function(){
var data_client = $('#data_client').val();
$.ajax({
type: "POST",
url: lotAjaxFiltreByClient,
data: { data_client: data_client },
success: function(response) {
var rep = response.split('||');
$('#data_prestation').html(rep[0]);
}
})
});
display in datatables:
var oTable = $('#lot_list').dataTable({
//'sAjaxSource': lotAjaxBrowseURL + "?filtre="+filtre+"&dataClient="+dataClient+"&dataPrestation="+dataPrestation+"&dataCommande="+dataCommande+"&dataDateRcpt="+dataDateRcpt+"&sendValSelect="+sendValSelect+"&sendValDate="+sendValDate+"&sendValChamp="+sendValChamp,
"bJQueryUI": true,
"bProcessing": true,
"bServerSide": true,
"bDestroy":true,
"sAjaxSource": lotAjaxBrowseURL,
"fnServerParams": function (aoData) {
aoData.push(
{ "name": "filtre", "value": dataSend[0] },
{ "name": "dataClient", "value": dataSend[1] },
{ "name": "dataPrestation", "value": dataSend[2] },
{ "name": "dataCommande", "value": dataSend[3] },
{ "name": "dataLot", "value": dataSend[4] },
{ "name": "dataStatutPli", "value": dataSend[5] },
{ "name": "dataDateRcpt", "value": dataSend[6] },
{ "name": "dataDateDebtmtcdt", "value": dataSend[7] },
{ "name": "dataDateFintmtcdt", "value": dataSend[8] },
{ "name": "sendValSelect", "value": dataSend[9] },
{ "name": "sendValDate", "value": dataSend[10] },
{ "name": "sendValChamp", "value": dataSend[11] }
);
},
'aoColumnDefs': [
{ 'bVisible': false,'sClass': 'center', 'bSearchable': true, 'aTargets': [ 0,5,10,11 ] },
{ 'sClass': 'center', 'aTargets': [ 3,4,6,7,8,9 ] }
],
'fnRowCallback': function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
$(nRow).addClass('dt-row-common');
},
'fnDrawCallback': function( oSettings ) {
$('#loading_data').css('display','none');
$('#lot_list_wrapper').css('z-index','0');
},
'oTableTools': {
'sSwfPath': lotFlashPath + '/copy_csv_xls_pdf.swf',
'aButtons': [
{
'sExtends': 'copy',
'sButtonText': 'Copier',
'mColumns': [ 0,1,2,3,4,5,6,7,8,9,10,11]
},
{
'sExtends': 'xls',
'sButtonText': 'Excel',
'mColumns': [ 1,2,3,4,5,6,7,8,9,10,11],
'sFileName': dtExportFilename + '.csv'
},
{
'sExtends': 'pdf',
'sButtonText': 'Pdf',
'fnCellRender': function ( sValue, iColumn ) {
//console.log(sValue+' ** '+iColumn);
return sValue;
},
'sPdfOrientation': 'landscape',
'sPdfMessage': now.toLocaleString().toUpperCase(),
'mColumns': "visible",
//'mColumns': [ 3,4,5,6,7,8,9,10,11],
'sFileName': dtExportFilename + '.pdf'
},
{
'sExtends': 'print',
'sButtonText': 'Imprimer',
'mColumns': [ 0,1,2,3,4,5,6,7,8,9,10,11]
}
]
},
'aaSorting': [[9, 'desc'],[6, 'desc']],
'sScrollY': calcDataTableHeight(),
//'sDom': 'T<"H"Cr>tS<"F"i>',
'sDom': 'T<"H"Cr>tS<"F"i>',
'bDeferRender': true,
'bRetrieve': true,
'bDestroy': true,
'bProcessing': true,
'bServerSide': true,
'bAutoWidth': true,
'bJQueryUI': true,
'bCaseSensitive': false,
'bCaseInsensitive' : true,
'bStateSave': true,
'sScrollX': '100%',
'sPaginationType': 'full_numbers',
'oColVis': {
'aiExclude': [ 0,3,4,6],
'buttonText': 'Afficher / masquer des colonnes',
'bRestore': true,
'sRestore': 'Afficher les colonnes initiales'
},
'oLanguage': {
'oPaginate': {
'sFirst': 'Début',
'sLast': 'Fin',
'sNext': 'Suivant',
'sPrevious': 'Précédent'
},
'sSearch': 'Rechercher',
'sProcessing': 'Chargement en cours...',
'sLengthMenu': 'Lignes affichées: <select>' +
'<option value="10">10</option>' +
'<option value="20">20</option>' +
'<option value="30">30</option>' +
'<option value="40">40</option>' +
'<option value="50">50</option>' +
'<option value="-1">Toutes</option>' +
'</select>',
'sZeroRecords': 'Aucun résultat pour cette recherche',
'sInfo': 'Lignes _START_ à _END_ (Total: _TOTAL_)',
'sInfoFiltered': ' - Filtrées parmis _MAX_ lignes',
'sInfoEmpty': 'Aucune donnée à afficher'
}
});
I tried many things but it does not work
Thanks a lot for your help
This question has accepted answers - jump to:
Answers
Can you link to the page showing the issue, as per the forum rules please. I'm having a hard time following what you want and why it isn't working!
Allan
Thanks a lot for your answers Allan.
I explain;
for example, I have a dropdown dependence like this one http://phppot.com/demo/jquery-dependent-dropdown-list-countries-and-states/ ; but the difference is what I use multiple select . Then I have data in the datatable like this one https://www.datatables.net/extensions/colvis/ ; what I would like to do is : when I select "Brazil" in the multiselect ; colvis display state in "Brazil" like ("Brazil_Saopolo","Brazil_riodejanero",.....); and when I selects "Brazil" and "China" in the multiselect , colvis displays "state" in "Brazil" and state in "China" with the prefixe like that "China_" and "Brazil_" (for example China_Beijing, Brazil_Saopolo and so on....) ; and so on...
is it possible to do that ??
thank you very much for your help and advice!!
You do understand that colVis controls the visibility of individual columns in your table?
Your examples are not making any sense. What exactly does your table look like?
It sounds like you want to use the grouping option for ColVis. With that you can specify multiple columns to show / hide with a single button.
Allan
Thanks a lot for your answer :
@Tangerine yes i understand that colVis controls the visibility of individual columns in my table but I use a join request; and i'd like to have the information of second table in colvis datatables is it possible ??
@Allan thanks a lot ; yes that is what I would like to do but . is it possible to change dynamically the "title" in option "groups" of colvis datatables , when i select and filter data in the select multiple as i describe in my previous comment.
thank you very much for your help , advice and answer
No. You can set the title at initialisation time, but not after.
The replacement for ColVis which will be out tomorrow will have an API that allows the button text to be chanced.
Allan