Validate an uploaded csv file using handsontable validator

666 Views Asked by At

Can i validate on client-side an uploaded csv file using handsontable validator after I have uploaded it? I used jquery-CSV as my file uploader and handsontable to display a table Here is my code:

            $(document).ready(function () {
            if (isAPIAvailable()) {
                $('#files').bind('change', handleFileSelect);
            }
        });

        function handleFileSelect(event) {
            var files = event.target.files;
            var file = files[0];
            printTable(file);
        }

        function printTable(file) {
            var reader = new FileReader();
            reader.readAsText(file);
            reader.onload = loadFileReader;
            reader.onerror = function () { alert('Unable to read ' + file.fileName); };
        }

        function loadFileReader(event) {
            var csv = event.target.result;
            var data = $.csv.toArrays(csv);

            $('#example').handsontable({
                data: data,
                minSpareRows: 1,
                colHeaders: false,
                contextMenu: true,
                cells: function (row, col, prop) {
                    var cellProperties = {};
                    cellProperties.readOnly = true;
                    return cellProperties;
                }
            });

        }
0

There are 0 best solutions below