使用handsontable验证器验证上载的csv文件

时间:2014-01-11 02:43:16

标签: jquery csv jquery-plugins handsontable jquery-csv

我可以在上传后使用双手验证器在客户端验证上传的csv文件吗? 我使用jquery-CSV作为文件上传器 和handsontable显示一个表格 这是我的代码:

            $(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 个答案:

没有答案
相关问题