framework easyui php excel datagrid jquery-easyui

php - framework - Exporte datagrid para sobresalir usando Jquery Easyui



demo easyui (2)

Soy nuevo en json. Genere datos jason de la tabla mysql utilizando php y deseo exportar el json generado al formato .xls.

examexport.php

<?php include ''conn.php''; $page = isset($_POST[''page'']) ? intval($_POST[''page'']) : 1; $rows = isset($_POST[''rows'']) ? intval($_POST[''rows'']) : 10; $semester = isset($_POST[''semester'']) ? mysql_real_escape_string($_POST[''semester'']) : ''''; $entry = isset($_POST[''entry'']) ? mysql_real_escape_string($_POST[''entry'']) : ''''; $batch = isset($_POST[''batch'']) ? mysql_real_escape_string($_POST[''batch'']) : ''''; //phpexcel things go here ?>

Mi php generó json:

{"total":"6","rows": [{"id":"2","regd":"25","name":"Lalhmangaihsangi","class":"BA", "rollno":"3","univ_roll":"UNVI573","univ_no":"MZU876","core":"Education", "semester":"First","batch":"2014","subject":"Education", "entry":"Second Internal Test","date":"2014-07-23", "score":"55","fm":"100","remark":"She is guarded"}]}

Código para exportar a excel:

<input type="button" onclick="exportExcel()" value="Export to Excel " /> <script> function exportExcel(){ $(''#dg'').datagrid(''load'',{ //load data by semester/batch/entry semester: $(''#semester'').val(), batch: $(''#batch'').val(), entry: $(''#entry'').val(), document.location=''excel/examexport.php''// How do I include entry/batch/ here? }); } </script>

Deseo enviar algo como document.location = ''excel / examexport.php? Entry = entry & batch = batch & semester = semestre'' Obtuve una excepción de ReferenceErrorExcel no está definida.


En su examexport.php, cambie $ _POST a $ _GET y use la siguiente función:

<input type="button" onclick="exportExcel()" value="Export to Excel " /> <script> function exportExcel() { var row=$(''#dg'').datagrid(''getData'');//to get the loaded data if (row) { url = "excel/examexport.php?entry="+$(''#entry'').val()+"& semester="+$(''#semester'').val()+"&batch="+$(''#batch'').val(); window.open(url); } } </script>

Para la palabra final, vaya a http://www.jeasyui.com/documentation/index.php . ellos tienen buena documentación.


$("#btnExport").click(function(e) { window.open(''data:application/vnd.ms-excel,'' + encodeURIComponent($(''#dg'').html())); e.preventDefault(); });

puedes usar un simple código jquery. debe agregar la biblioteca jquery en su archivo.