<commit_before>function getPersonFilter() {
    function PersonFilter() {
    }

    PersonFilter.prototype.init = function (params) {
        this.valueGetter = params.valueGetter;
        this.filterText = null;
        this.setupGui(params);
    };

    // not called by ag-Grid, just for us to help setup
    PersonFilter.prototype.setupGui = function (params) {
        this.gui = document.createElement('div');
        this.gui.innerHTML =
            '<div style="padding: 4px;">' +
            '<div style="font-weight: bold;">Custom Athlete Filter</div>' +
            '<div><input style="margin: 4px 0px 4px 0px;" type="text" id="filterText" placeholder="Full name search..."/></div>' +
            '<div style="margin-top: 20px; width: 200px;">This filter does partial word search on multiple words, eg "<NAME>" still brings back <NAME>.</div>' +
            '</div>';

        this.eFilterText = this.gui.querySelector('#filterText');
        this.eFilterText.addEventListener("changed", listener);
        this.eFilterText.addEventListener("paste", listener);
        this.eFilterText.addEventListener("input", listener);
        // IE doesn't fire changed for special keys (eg delete, backspace), so need to
        // listen for this further ones
        this.eFilterText.addEventListener("keydown", listener);
        this.eFilterText.addEventListener("keyup", listener);

        var that = this;

        function listener(event) {
            that.filterText = event.target.value;
            params.filterChangedCallback();
        }
    };

    PersonFilter.prototype.getGui = function () {
        return this.gui;
    };

    PersonFilter.prototype.doesFilterPass = function (params) {
        // make sure each word passes separately, ie search for firstname, lastname
        var passed = true;
        var valueGetter = this.valueGetter;
        this.filterText.toLowerCase().split(" ").forEach(function (filterWord) {
            var value = valueGetter(params);
            if (value.toString().toLowerCase().indexOf(filterWord) < 0) {
                passed = false;
            }
        });

        return passed;
    };

    PersonFilter.prototype.isFilterActive = function () {
        var isActive = this.filterText !== null && this.filterText !== undefined && this.filterText !== '';
        return isActive;
    };

    PersonFilter.prototype.getApi = function () {
        var that = this;
        return {
            getModel: function () {
                var model = {value: that.filterText.value};
                return model;
            },
            setModel: function (model) {
                that.eFilterText.value = model.value;
            }
        };
    };

    PersonFilter.prototype.getModelAsString = function (model) {
        return model ? model : '';
    };

    PersonFilter.prototype.getModel = function () {
        return this.filterText;
    };
    // lazy, the example doesn't use setModel()
    PersonFilter.prototype.setModel = function () {
    };

    return PersonFilter;
}

var columnDefs = [
    {headerName: "Athlete", field: "athlete", width: 150, filter: getPersonFilter(), suppressMenu: true},
    {headerName: "Age", field: "age", width: 90, filter: 'agNumberColumnFilter', suppressMenu: true},
    {headerName: "Country", field: "country", width: 120, filter: 'agSetColumnFilter', suppressMenu: true},
    {headerName: "Year", field: "year", width: 90, filter: 'agNumberColumnFilter', suppressMenu: true},
    {
        headerName: "Date", field: "date", width: 170, filter: 'agDateColumnFilter', filterParams: {
            comparator: function (filterLocalDateAtMidnight, cellValue) {
                var dateAsString = cellValue;
                if (dateAsString == null) return -1;
                var dateParts = dateAsString.split("/");
                var cellDate = new Date(Number(dateParts[2]), Number(dateParts[1]) - 1, Number(dateParts[0]));

                if (filterLocalDateAtMidnight.getTime() == cellDate.getTime()) {
                    return 0;
                }

                if (cellDate < filterLocalDateAtMidnight) {
                    return -1;
                }

                if (cellDate > filterLocalDateAtMidnight) {
                    return 1;
                }
            },
            browserDatePicker: true
        }, suppressMenu: true
    },
    {headerName: "Sport", field: "sport", width: 110, suppressMenu: true, filter: 'agTextColumnFilter'},
    {
        headerName: "Gold",
        field: "gold",
        width: 100,
        filter: 'agNumberColumnFilter',
        filterParams: {applyButton: true},
        suppressMenu: true
    },
    {
        headerName: "Silver",
        field: "silver",
        width: 100,
        filter: 'agNumberColumnFilter',
        floatingFilterComponentParams: {suppressFilterButton: true}
    },
    {
        headerName: "Bronze",
        field: "bronze",
        width: 100,
        filter: 'agNumberColumnFilter',
        floatingFilterComponentParams: {suppressFilterButton: true}
    },
    {headerName: "Total", field: "total", width: 100, filter: false}
];

var gridOptions = {
    defaultColDef: {
        sortable: true,
        filter: true
    },
    floatingFilter: true,
    columnDefs: columnDefs,
    rowData: null
};

function irelandAndUk() {
    var countryFilterComponent = gridOptions.api.getFilterInstance('country');
    countryFilterComponent.selectNothing();
    countryFilterComponent.selectValue('Ireland');
    countryFilterComponent.selectValue('Great Britain');
    gridOptions.api.onFilterChanged();
}

function clearCountryFilter() {
    var countryFilterComponent = gridOptions.api.getFilterInstance('country');
    countryFilterComponent.selectEverything();
    gridOptions.api.onFilterChanged();
}

function destroyCountryFilter() {
    gridOptions.api.destroyFilter('country');
}

function endingStan() {
    var countryFilterComponent = gridOptions.api.getFilterInstance('country');
    countryFilterComponent.selectNothing();
    for (var i = 0; i < countryFilterComponent.getUniqueValueCount(); i++) {
        var value = countryFilterComponent.getUniqueValue(i);
        var valueEndsWithStan = value.indexOf('stan') === value.length - 4;
        if (valueEndsWithStan) {
            countryFilterComponent.selectValue(value);
        }
    }
    gridOptions.api.onFilterChanged();
}

function setCountryModel() {
    var countryFilterComponent = gridOptions.api.getFilterInstance('country');
    var model = {
        type: 'set',
        values: ['Algeria', 'Argentina']
    };<commit_msg>AG-3390 - fixed floating filters example<commit_after>function getPersonFilter() {
    function PersonFilter() {
    }

    PersonFilter.prototype.init = function (params) {
        this.valueGetter = params.valueGetter;
        this.filterText = null;
        this.setupGui(params);
    };

    // not called by ag-Grid, just for us to help setup
    PersonFilter.prototype.setupGui = function (params) {
        this.gui = document.createElement('div');
        this.gui.innerHTML =
            '<div style="padding: 4px;">' +
            '<div style="font-weight: bold;">Custom Athlete Filter</div>' +
            '<div><input style="margin: 4px 0px 4px 0px;" type="text" id="filterText" placeholder="Full name search..."/></div>' +
            '<div style="margin-top: 20px; width: 200px;">This filter does partial word search on multiple words, eg "mich phel" still brings back <NAME>.</div>' +
            '</div>';

        this.eFilterText = this.gui.querySelector('#filterText');
        this.eFilterText.addEventListener("changed", listener);
        this.eFilterText.addEventListener("paste", listener);
        this.eFilterText.addEventListener("input", listener);
        // IE doesn't fire changed for special keys (eg delete, backspace), so need to
        // listen for this further ones
        this.eFilterText.addEventListener("keydown", listener);
        this.eFilterText.addEventListener("keyup", listener);

        var that = this;

        function listener(event) {
            that.filterText = event.target.value;
            params.filterChangedCallback();
        }
    };

    PersonFilter.prototype.getGui = function () {
        return this.gui;
    };

    PersonFilter.prototype.doesFilterPass = function (params) {
        // make sure each word passes separately, ie search for firstname, lastname
        var passed = true;
        var valueGetter = this.valueGetter;
        this.filterText.toLowerCase().split(" ").forEach(function (filterWord) {
            var value = valueGetter(params);
            if (value.toString().toLowerCase().indexOf(filterWord) < 0) {
                passed = false;
            }
        });

        return passed;
    };

    PersonFilter.prototype.isFilterActive = function () {
        var isActive = this.filterText !== null && this.filterText !== undefined && this.filterText !== '';
        return isActive;
    };

    PersonFilter.prototype.getApi = function () {
        var that = this;
        return {
            getModel: function () {
                var model = {value: that.filterText.value};
                return model;
            },
            setModel: function (model) {
                that.eFilterText.value = model.value;
            }
        };
    };

    PersonFilter.prototype.getModelAsString = function (model) {
        return model ? model : '';
    };

    PersonFilter.prototype.getModel = function () {
        return this.filterText;
    };
    // lazy, the example doesn't use setModel()
    PersonFilter.prototype.setModel = function () {
    };

    return PersonFilter;
}

var columnDefs = [
    {headerName: "Athlete", field: "athlete", width: 150, filter: getPersonFilter(), suppressMenu: true},
    {headerName: "Age", field: "age", width: 90, filter: 'agNumberColumnFilter', suppressMenu: true},
    {headerName: "Country", field: "country", width: 120, filter: 'agSetColumnFilter', suppressMenu: true},
    {headerName: "Year", field: "year", width: 90, filter: 'agNumberColumnFilter', suppressMenu: true},
    {
        headerName: "Date", field: "date", width: 170, filter: 'agDateColumnFilter', filterParams: {
            comparator: function (filterLocalDateAtMidnight, cellValue) {
                var dateAsString = cellValue;
                if (dateAsString == null) return -1;
                var dateParts = dateAsString.split("/");
                var cellDate = new Date(Number(dateParts[2]), Number(dateParts[1]) - 1, Number(dateParts[0]));

                if (filterLocalDateAtMidnight.getTime() == cellDate.getTime()) {
                    return 0;
                }

                if (cellDate < filterLocalDateAtMidnight) {
                    return -1;
                }

                if (cellDate > filterLocalDateAtMidnight) {
                    return 1;
                }
            },
            browserDatePicker: true
        }, suppressMenu: true
    },
    {headerName: "Sport", field: "sport", width: 110, suppressMenu: true, filter: 'agTextColumnFilter'},
    {
        headerName: "Gold",
        field: "gold",
        width: 100,
        filter: 'agNumberColumnFilter',
        filterParams: {applyButton: true},
        suppressMenu: true
    },
    {
        headerName: "Silver",
        field: "silver",
        width: 100,
        filter: 'agNumberColumnFilter',
        floatingFilterComponentParams: {suppressFilterButton: true}
    },
    {
        headerName: "Bronze",
        field: "bronze",
        width: 100,
        filter: 'agNumberColumnFilter',
        floatingFilterComponentParams: {suppressFilterButton: true}
    },
    {headerName: "Total", field: "total", width: 100, filter: false}
];

var gridOptions = {
    defaultColDef: {
        sortable: true,
        filter: true
    },
    floatingFilter: true,
    columnDefs: columnDefs,
    rowData: null
};

function irelandAndUk() {
    var countryFilterComponent = gridOptions.api.getFilterInstance('country');
    countryFilterComponent.selectNothing();
    countryFilterComponent.selectValue('Ireland');
    countryFilterComponent.selectValue('Great Britain');
    countryFilterComponent.applyModel();
    gridOptions.api.onFilterChanged();
}

function clearCountryFilter() {
    var countryFilterComponent = gridOptions.api.getFilterInstance('country');
    countryFilterComponent.selectEverything();
    countryFilterComponent.applyModel();
    gridOptions.api.onFilterChanged();
}

function destroyCountryFilter() {
    gridOptions.api.destroyFilter('country');
}

function endingStan() {
    var countryFilterComponent = gridOptions.api.getFilterInstance('country');
    countryFilterComponent.selectNothing();
    for (var i = 0; i < countryFilterComponent.getUniqueValueCount(); i++) {
        var value = countryFilterComponent.getUniqueValue(i);
        var valueEndsWithStan = value.indexOf('stan') === value.length - 4;
        if (valueEndsWithStan) {
            countryFilterComponent.selectValue(value);
        }
    }
    countryFilterComponent.applyModel();
    gridOptions.api.onFilterChanged();
}

function setCountryModel() {
    var countryFilterComponent = gridOptions.api.getFilterInstance('country');
    var model = {
        type: 'set',
        values: ['Algeria', 'Argentina']
    };
{'fraction_non_alphanumeric': 0.12188365650969529, 'fraction_numerical': 0.007636445309575504, 'mean_word_length': 2.540418764908561, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4157623', 'n_tokens_mistral': 3689, 'n_tokens_neox': 3532, 'n_words': 822}