CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: HTML

Reordering invoice lines using jqGrid and TableDND extension

391 Views
Copy Code Show/Hide Line Numbers
   1:  jQuery("#list").tableDnD({
   2:   
   3:      onDrop: function(table, row) {
   4:   
   5:          var oldIndex = row.id;
   6:   
   7:          var newIndex = row.rowIndex;
   8:   
   9:          if (oldIndex == newIndex)
  10:   
  11:              return;
  12:   
  13:   
  14:   
  15:          $.post('/accounting/invoice/<%= Model.Invoice.Id %>/changeroworder',
  16:   
  17:          {
  18:   
  19:              oldPosition: oldIndex,
  20:   
  21:              newPosition: newIndex
  22:   
  23:          },
  24:   
  25:          function(result) {
  26:   
  27:              $("#list").trigger("reloadGrid");
  28:   
  29:          });
  30:   
  31:      }
  32:   
  33:  });
  34:   
  35:   
  36:   
  37:   
  38:  public void ChangeLineOrder(int oldPosition, int newPosition)
  39:   
  40:  {
  41:   
  42:      var invoice = GetById(1); // changedLine.ParentInvoice;
  43:   
  44:   
  45:   
  46:      var moveUp = (newPosition < oldPosition);
  47:   
  48:      var transaction = _session.BeginTransaction();
  49:   
  50:   
  51:   
  52:      foreach (var line in invoice.Lines)
  53:   
  54:      {
  55:   
  56:          if(line.LineNo == oldPosition)
  57:   
  58:          {
  59:   
  60:              line.LineNo = newPosition;
  61:   
  62:              continue;
  63:   
  64:          }
  65:   
  66:          if (moveUp)
  67:   
  68:              if (line.LineNo < newPosition || line.LineNo > oldPosition)
  69:   
  70:                  continue;
  71:   
  72:              else
  73:   
  74:                  line.LineNo++;
  75:   
  76:          else
  77:   
  78:              if (line.LineNo > newPosition || line.LineNo < oldPosition)
  79:   
  80:                  continue;
  81:   
  82:              else
  83:   
  84:                  line.LineNo--;
  85:   
  86:      }
  87:   
  88:      Save(invoice);
  89:   
  90:      transaction.Commit();
  91:   
  92:  }
  93:   
by ZStyle
  August 24, 2010 @ 11:16pm
Tags:
Description:
http://weblogs.asp.net/gunnarpeipman/archive/2009/07/22/reordering-invoice-lines-using-jqgrid-and-tablednd-extension.aspx

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate