0

I have a very basic jqGrid table (#list) which contains a column: actions. I somehow figure out how to add custom functions but don't know how to generate the code to duplicate its content (if possible using addrowData method). Here is my code so far:

(...)
    gridComplete: function () {
    var grid = jQuery("#list");
    var ids = grid.jqGrid('getDataIDs');
    //console.log(ids);
    for (var i = 0; i < ids.length; i++) {
        var rowId = ids[i];

        var cbutton = "<input style='height:22px;width:75px;' " + "type='button' value='Duplicate' " + "onclick=\"Duplicate('#list'," + rowId + ");\" />";
        grid.jqGrid('setRowData', rowId, {
            action: cbutton
        });
    }
(...)

and the custom function Duplicate:

    Duplicate = function (table, Id) {
            console.log(table);//#list
            console.log(Id);//whatever row Id clicked
//need a way to duplicate the row

        }

I guess I might pass all values to the function as arguments, create a new Row using addrowData and then perform a foreach to fill in the rows with data (myData).

Any clues?

Faraderegele
  • 187
  • 4
  • 14
  • what is your question? want to add custom buttons in each row?http://stackoverflow.com/questions/11743983/adding-a-custom-button-in-row-in-jqgrid/11744722#11744722 look at this answer, want to cpoy a row?? http://stackoverflow.com/questions/11923237/jqgrid-how-to-copy-a-row/11923386#11923386 look at this answer – Piyush Sardana Sep 03 '12 at 14:07
  • The question was stated in the title. Sorry for being unclear. Thanks for the suggestion. – Faraderegele Sep 04 '12 at 09:08

1 Answers1

0

Here is the solution I found myself and it works well:

 Duplicate = function (table, Id) {
   newId = null;
   myData = jQuery(table).getLocalRow(Id);//or getRowData(Id)
   jQuery(table).jqGrid('addRowData', newId, myData, "after", Id);
   }
Faraderegele
  • 187
  • 4
  • 14