0

I have a jqgrid like this

colNames: ['Name','Actions'],

 colModel: [

        { name: 'name', index: 'name', align: 'right', editable: true},
{ name: 'act', index: 'act', width: 75, align: 'center', sortable: false, formatter: 'actions',formatoptions: {keys: true,delbutton:false}}
],

now i want to add a custom button along with edit button of action formatter.

I have tried this, doesnt seem to be working, any guesses why?

gridComplete: function(){
    var ids = $("#grid").jqGrid('getDataIDs');
    for(var i=0;i < ids.length;i++){
        var cl = ids[i];
        alert(cl);
        be = "<input style='height:22px;' type='button' value='Edit' onclick=\"window.location.href='editItem.asp?ID="+cl+"'\"  />";

        $("#grid").jqGrid('setRowData',ids[i],{act:be});
    }   
},
Eonasdan
  • 7,563
  • 8
  • 55
  • 82
Piyush Sardana
  • 1,748
  • 4
  • 19
  • 33
  • I think you should write your own formatter becaause you don't use the delete action, and you want to custom the edit button. – jbrtrnd Jul 06 '12 at 12:22
  • no, i want to keep my edit button as it is, plus i want to add one more button along with edit. So can you give me any examples on it? – Piyush Sardana Jul 06 '12 at 14:40

2 Answers2

2

If I understand correct your requirements you will find the answer on your question in this and this old answers.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • thanks sir, u r a life saver...that it exactly i was looking for...and believe me or not, i was waiting for you answers..thanks you..:) – Piyush Sardana Jul 07 '12 at 17:38
1

This is an example of a custom formatter (assuming you set the value of the "Actions" col with your item id) :

<script>
    var myCustomFormatter = function(cellVal,options,rowObject) {
        return "<input style='height:22px;' type='button' value='Edit' onclick=\"window.location.href='editItem.asp?ID="+cellVal+"'\"  />";  
    };

    $("#yourTableID").jqGrid({
        ....
        colNames: [....,'Actions'],
        colModel: [
            ....
            { name: 'act', index: 'act', width: 75, align: 'center', sortable: false, formatter:myCustomFormatter}
        ],
        ....
    });

</script>

Read the jqGrid documentation about custom formatter.

jbrtrnd
  • 3,815
  • 5
  • 23
  • 41
  • just want to ask this question, can both action formatter and custom formatter go together?? i'll implement this when i get code access... – Piyush Sardana Jul 06 '12 at 15:19
  • @PiyushSardana, I don't think, you can maybe extend the action formatter in jqGrid source. – jbrtrnd Jul 06 '12 at 15:32
  • are you sure about it? cause if u are true then i think i'll implement those changes, but u sure there is no other way around? – Piyush Sardana Jul 06 '12 at 15:40
  • @PiyushSardana In my mind, the simpliest way is to write your own custom formatter :) ! Ask on jqGrid forum, if you need more informations, I can't help you anymore, sorry. – jbrtrnd Jul 06 '12 at 15:50