Is there an easy way to change the value of the tfoot?

Is there an easy way to change the value of the tfoot?

GeoffreyGeoffrey Posts: 19Questions: 5Answers: 0
edited March 2016 in Free community support

Hello, I would to know if there is an easy way to change the value of the input on a tfoot (the column is fixed).

At the moment, I initialize my tfoot like that:

$('#table_liste_materiel tfoot th').each( function (i) {
            var title = $(this).text();
            if (title!='')  $(this).html( '<input id="input_table_liste_materiel_'+i+'" type="text" size=10 placeholder="'+title+'" data-index="'+i+'" />' );
        } ); 

Then, I launch this function when the user click on a button:


function afficher_document_pour_num_iple(num_iple) { $("#tabs").tabs({active: 4}); $("div#onglet_documentation.ui-tabs-panel.ui-widget-content.ui-corner-bottom table.cell-border.hover.display.nowrap.dataTable.DTFC_Cloned tfoot tr th input#input_table_liste_documentation_0").val(num_iple); table_liste_documentation .columns(0) .search(num_iple) .draw(); }

This is working well ... but the way to change the value of the input is quite dirty ... ^^

Is there a better way ? =)

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin

    The selector is certainly excessive - you can probably reduce that significantly. For example there is no point in in using an id selector as well as the tag name and class names, since the id must be unique!

    But at the moment, that's probably about as good as it gets.

    One thing to note - you need to be really careful about putting input elements into the fixed columns (or fixed headers) since they will be rewritten when the table redraws. I would generally recommend you avoid it.

    Allan

  • GeoffreyGeoffrey Posts: 19Questions: 5Answers: 0

    Thank you for your answer Allan.

    The problem is that I want to indicate to the user that there is a filter and where ... The best way to do that (in my opinion) is to change the value of the input...

    Because the search function is working very well, yes. But the user need to know that he must write something on the input of the first column to clear to filter...

    Also, is it possible to search and show an exact value ? For example if I want to show the row where the value is "20" in the first column, I don't want to see others row with 120, 220, 10205 ....
    But I want this only for the first column because the first colum is like the "id" =)

    Geoffrey

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    Answer ✓

    Also, is it possible to search and show an exact value ?

    Yes - use a regular expression: table.column( 0 ).search( '^20$', true, false );

    Allan

  • GeoffreyGeoffrey Posts: 19Questions: 5Answers: 0

    Ok thank you ! I did that:

    $(table_liste_materiel.table().container()).on('keyup', 'tfoot input', function () {
                if($(this).data('index')==0 && this.value!=""){
                    table_liste_materiel
                        .column($(this).data('index'))
                        .search('^'+this.value+'$', true, false)
                        .draw();
                }
                else {
                    table_liste_materiel
                        .column($(this).data('index'))
                        .search(this.value)
                        .draw();
                }
            });
    
This discussion has been closed.