This is for fetching data from database
def im():
task=db(db.mydb).select()
return dict(rows=task)
For importing file from database
def import_table():
form = SQLFORM.factory(Field('table',requires=IS_IN_SET(db.tables)),
Field('csvfile','upload',uploadfield=False))
form.process()
if form.accepted:
try:
db[form.vars.table].import_from_csv_file(request.vars.csvfile.file)
except: form.errors.csvfile = 'invalid file'
return dict(form=form)
The View part
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css"
href="http://www.jeasyui.com/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
href="http://www.jeasyui.com/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css"
href="http://www.jeasyui.com/easyui/demo/demo.css">
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.6.min.js"></script>
<script type="text/javascript"
src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript"
src="http://www.jeasyui.com/easyui/jquery.edatagrid.js"></script>
<script type="text/javascript">
$(function(){
$('#dg').edatagrid({
saveUrl: 'save_user.php',
updateUrl: 'update_user.php', I am not able to perform these
function
destroyUrl: 'destroy_user.py'
});
});
</script>
</head>
<body>
<h2>CRUD DataGrid</h2>
<div class="demo-info" style="margin-bottom:10px">
<div class="demo-tip icon-tip"> </div>
<div>Double click the row to begin editing.</div>
</div>
<table id="dg" title="My Users"
style="width:700px;height:250px"toolbar="#toolbar" pagination="true"
idField="id"rownumbers="true" fitColumns="true" singleSelect="true">
<thead>
<tr>
<th field="firstname" width="50"
editor="{type:'validatebox',options:{required:true}}">Name</th>
<th field="lastname" width="50"
editor="{type:'validatebox',options:{required:true}}">Phone</th>
<th field="phone" width="50" editor="text">Email</th>
<th field="email" width="50"
editor="{type:'validatebox',options:{required:true}}">Mobile</th>
</tr>
</thead>
<tbody> {{for i,row in enumerate(rows):}}
<tr>
<td>{{=row.name}}</td>
<td >{{=row.phone}}</td>
<td >{{=row.email}}</td>
<td >{{=row.mobile}}</td>
</tr> {{pass}}
</tbody>
</table>
<div id="toolbar">
<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true"
onclick="javascript:$('#dg').edatagrid('addRow')">New</a>
<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true"
onclick="javascript:$('#dg').edatagrid('destroyRow')">Destroy</a>
<a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true"
onclick="javascript:$('#dg').edatagrid('saveRow')">Save</a>
<a href="#" class="easyui-linkbutton" iconCls="icon-undo" plain="true"
onclick="javascript:$('#dg').edatagrid('cancelRow')">Cancel</a>
<a href="{{=URL('default','import_table')}}" class="easyui-linkbutton"
iconCls="icon-undo" plain="true" >Import</a>
</div>
</body>
</html>
Anthony if u can do some thing on that then it is very great for me thanks
On Thursday, 27 June 2013 10:42:00 UTC+5:30, Rohitraj Sharma wrote:
>
>
> Hi Anthony
>
> I am not able to get your question. I have one form controller with one
> view. http://127.0.0.1:8000/tracker/default/form when i run this url its
> show 404 error.
> Actually what is my requirement, I have one csv file. which i have to
> upload. Before saving the file in database, i want to edit in browser.
> After editing i want to save in database. Is there any method to do.
> Thanks
>
> On Wednesday, 26 June 2013 19:09:00 UTC+5:30, Anthony wrote:
>>
>> Using the browser developer tools, what URL gets requested when the ajax
>> call is made?
>>
>> On Wednesday, June 26, 2013 2:44:18 AM UTC-4, Rohitraj Sharma wrote:
>>>
>>> I want to select some particular table from database in a drop dowan.
>>> Then import csv file. edit that file and update. . Can Any one can help me
>>> plz
>>>
>>> i am using the fallowing code for that
>>>
>>>
>>> View
>>>
>>> <script>
>>> jQuery(function() {
>>> jQuery('#table').change(function() {
>>> web2py_component("{{=URL('default', 'form.load')}}" + "/" +
>>> jQuery(this).val(), target='form')
>>> })})</script>
>>> {{=SELECT('Select a table', *db.tables, _id='table')}}<div id="form"></div>
>>>
>>>
>>> Controller
>>>
>>> def form():
>>> if request.args(0) in db.tables:
>>> response.generic_patterns = ['load']
>>> return dict(form=SQLFORM(db[request.args(0)]).process())
>>> else:
>>> raise HTTP(404)
>>>
>>>
>>> every time it toll else part.
>>>
>>>
>>> can any one help me.
>>>
>>>
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.