Quantcast

Save data inside html table at once

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Save data inside html table at once

didinj
Hi all,

I have this table


which generated by jquery
function getProduct(data) {
    var rows = data.length
    var htm = '';
    for(i=0;i<rows;i++) {
      htm+='<tr><td><input type="text" name="plu'+i+'" value="'+data[i].plu+'" /></td><td><input type="text" name="description'+i+'" value="'+data[i].description+'" /></td><td><input type="text" name="cost'+i+'" id="cost'+i+'" value="'+data[i].cost+'" /></td><td><input type="text" name="qty'+i+'" id="qty'+i+'" value="" onkeyup="sumtcost(\''+i+'\')" /></td><td><input type="text" name="tcost'+i+'" id="tcost'+i+'" value="" /></td></tr>';
    }
    $("#orderdetail-tbody").html(htm);
  }

My question is how to make controller to save input text value in that table at once?

Thanks,
Didin
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Save data inside html table at once

';
    }
    $("#orderdetail-tbody").html(htm);
  }

Now I create controller for save data:
def i = 0
while (params."${i}.plu") {
    new PurchaseDetail(plu:params."${i}.plu",description:params."${i}.description",cost:params."${i}.cost",qty:params."${i}.qty",tcost:params."${i}.tcost").save(flush:true)
    i++
} 

But, nothing saved in PurchaseDetail table. Please, help me solve this problem.
didinj
I have change input name in jquery:
function getProduct(data) {
    var rows = data.length
    var htm = '';
    for(i=0;i<rows;i++) {
      htm+='<tr>
<input type="text" name="'+i+'.plu" value="'+data[i].plu+'" /><input type="text" name="'+i+'.description" value="'+data[i].description+'" /><input type="text" name="'+i+'.cost" id="cost'+i+'" value="'+data[i].cost+'" /><input type="text" name="'+i+'.qty" id="qty'+i+'" value="" onkeyup="sumtcost(\''+i+'\')" /><input type="text" name="'+i+'.tcost" id="tcost'+i+'" value="" />
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Save data inside html table at once

Jonathan Rosenberg-2

This question has a bunch of moving parts and we only see a piece or two here, so its hard to help much.

But, first things first.  Are you sure your jQuery/HTML is correct?

On Jul 17, 2012 6:35 AM, "didinj" <[hidden email]> wrote:
I have change input name in jquery:
function getProduct(data) {
    var rows = data.length
    var htm = '';
    for(i=0;i<rows;i++) {
      htm+='&lt;tr>     <input type="text" name="'+i+'.plu"
value="'+data[i].plu+'" />      <input type="text" name="'+i+'.description"
value="'+data[i].description+'" />      <input type="text" name="'+i+'.cost"
id="cost'+i+'" value="'+data[i].cost+'" />      <input type="text"
name="'+i+'.qty" id="qty'+i+'" value="" onkeyup="sumtcost(\''+i+'\')" />
<input type="text" name="'+i+'.tcost" id="tcost'+i+'" value="" />';
    }
    $("#orderdetail-tbody").html(htm);
  }

Now I create controller for save data:


But, nothing saved in PurchaseDetail table. Please, help me solve this
problem.

--
View this message in context: http://grails.1312388.n4.nabble.com/Save-data-inside-html-table-at-once-tp4631567p4631641.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Save data inside html table at once

didinj
Thanks,
Yes, it's correct and I catch all params post by those jquery table.
Here's full save method:
def save() {
        def purchaseInstance = new Purchase(params)
        if (!purchaseInstance.save(flush: true)) {
            render(view: "create", model: [purchaseInstance: purchaseInstance])
            return
        }
        def i=0
        while(params."${i}.plu") {
            new PurchaseDetail(purchase:purchaseInstance.id,plu:params."${i}.plu",description:params."${i}.description",qty:params."${i}.qty",cost:params."${i}.cost",tcost:params."${i}.tcost").save(flush: true)
            System.out.println(purchaseInstance.id)
            i++
        }
        flash.message = message(code: 'default.created.message', args: [message(code: 'purchase.label', default: 'Purchase'), purchaseInstance.id])
        redirect(action: "show", id: purchaseInstance.id)
    }

I don't know why It can save data and no error throws.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Save data inside html table at once

Jonathan Rosenberg-2
Well, there's your problem, there's no code :-)

--
Jonathan Rosenberg
Founder & Executive Director
Tabby's Place, a Cat Sanctuary
http://www.tabbysplace.org/


On Jul 17, 2012, at 7:11 PM, didinj <[hidden email]> wrote:

> Thanks,
> Yes, it's correct and I catch all params post by those jquery table.
> Here's full save method:
>
>
> I don't know why It can save data and no error throws.
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/Save-data-inside-html-table-at-once-tp4631567p4631697.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Save data inside html table at once

didinj
Please explain "no code", or Grails only can save data one by one?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Save data inside html table at once

OverZealous
In reply to this post by didinj
FYI: there's a bug in the Nabble interface where code blocks (<pre> sections) are not sent to the mailing list.  Your message is below, and it looks like you "forgot" to copy the code block in.  It's there, just not in the mailing list.

If someone wants to see the code, visit Nabble: http://grails.1312388.n4.nabble.com/Save-data-inside-html-table-at-once-td4631567.html#a4631697

- Phil DeJarnett

didinj wrote:
> Thanks,
> Yes, it's correct and I catch all params post by those jquery table.
> Here's full save method:
>
>
> I don't know why It can save data and no error throws.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Save data inside html table at once

didinj
OK, I rewrite the codes.
Jquery:
function getProduct(data) {
    var rows = data.length
    var htm = '';
    for(i=0;i<rows;i++) {
      htm+='&lt;tr>     <input type="text" name="'+i+'.plu"
value="'+data[i].plu+'" />      <input type="text" name="'+i+'.description"
value="'+data[i].description+'" />      <input type="text" name="'+i+'.cost"
id="cost'+i+'" value="'+data[i].cost+'" />      <input type="text"
name="'+i+'.qty" id="qty'+i+'" value="" onkeyup="sumtcost(\''+i+'\')" />
<input type="text" name="'+i+'.tcost" id="tcost'+i+'" value="" />';
    }
    $("#orderdetail-tbody").html(htm);
  }

and Controller:
def save() {
        def purchaseInstance = new Purchase(params)
        if (!purchaseInstance.save(flush: true)) {
            render(view: "create", model: [purchaseInstance: purchaseInstance])
            return
        }
        def i=0
        while(params."${i}.plu") {
            new PurchaseDetail(purchase:purchaseInstance.id,plu:params."${i}.plu",description:params."${i}.description",qty:params."${i}.qty",cost:params."${i}.cost",tcost:params."${i}.tcost").save(flush: true)
            System.out.println(purchaseInstance.id)
            i++
        }
        flash.message = message(code: 'default.created.message', args: [message(code: 'purchase.label', default: 'Purchase'), purchaseInstance.id])
        redirect(action: "show", id: purchaseInstance.id)
    }

Now someone tell me why it can't save data to database?
Loading...