EditableGrid - How to make every column header into individual filter

643 Views Asked by At

I am using EditableGrid (http://www.editablegrid.net/) Which creates some nice looking Editable tables

I'm Trying to modify the table header to make them into Individual filters like in example - https://phppot.com/demo/column-search-in-datatables-using-server-side-processing/

Current Filter textbox works very nicely but has a limit for searching one value for all columns.

I find many solutions for an individual column filter but I don't want to use other tables as they do not provide inline table editing functionality with dropdown and date picker, Is there a way I can implement it in EditableGrid?

I have also Asked this Question on Github (https://github.com/webismymind/editablegrid-mysql-example/issues/66) but the thread is not been active for a long time so I have very little hope of getting a solution from there.

1

There are 1 best solutions below

11
Stefan Avramovic On

In index.html update this code: see where //new code ---- starts and //new code ---- ends, try it out..

<script type="text/javascript">

                var datagrid; 

                window.onload = function() { 
                  datagrid = new DatabaseGrid();

//new code ---- starts 

var list = document.getElementsByTagName("thead")[0];
for(var i = -1; i < list.childNodes.length; i++){

    var input = document.createElement("input");
                input.type = "text";
                input.className = "filter";
  list.getElementsByTagName("th")[i+1].appendChild(input);
}
var z = document.getElementsByClassName('filter')
for(var i = 0; i< z.length; i++){
  z[i].addEventListener("input", function(e){      

  datagrid.editableGrid.filter( e.target.parentNode.querySelector("input").value, [i]);
  })
}  

//new code ---- ends

                    // key typed in the filter field
                    $("#filter").keyup(function() {
                      datagrid.editableGrid.filter( $(this).val());
                        // To filter on some columns, you can set an array of column index 
                        //datagrid.editableGrid.filter( $(this).val(), [0,3,5]);
                      });
                    $("#showaddformbutton").click( function()  {
                      showAddForm();
                    });
                    $("#cancelbutton").click( function() {
                      showAddForm();
                    });
                    $("#addbutton").click(function() {
                      datagrid.addRow();
                    });


        } 
    $(function () { 
        });
            </script>