Skip to main content

Sortable Grid, with Move Up and Down buttons

Comments

1 comment

  • John Sweazen

    I have used Sortable javascript plugin for its flexibility. 

    https://github.com/SortableJS/Sortable

    Super simplified example

    <Report ID="Sharetec.Sortable">
      <StyleSheet StyleSheet="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
      <StyleSheet StyleSheet="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" />
      <IncludeScriptFile IncludedScriptFile="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js" />
      <IncludeScriptFile IncludedScriptFile="sortable.js" />
      <IncludeScriptFile IncludedScriptFile="https://cdn.jsdelivr.net/npm/jquery-sortablejs@latest/jquery-sortable.js" />
      <Body>
        <IncludeHtml Html="&lt;style&gt;&#xD;&#xA;.handle {&#xD;&#xA;    cursor: grab;&#xD;&#xA;}&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;&lt;/style&gt;&#xD;&#xA;" />
        <InputText ID="finalorder" />
        <DataTable ID="items-2" Width="100" WidthScale="%">
          <DataLayer Type="Static">
            <StaticDataRow Desc="Item 1" />
            <StaticDataRow Desc="Item 2" />
            <StaticDataRow Desc="Item 3" />
            <StaticDataRow Desc="Item 4" />
            <StaticDataRow Desc="Item 5" />
            <GroupFilter GroupColumn="SortOrder" ID="gfSortOrder" KeepGroupedRows="True" />
            <SequenceColumn ID="SortOrder" />
          </DataLayer>
          <DataTableColumn Header="SortOrder">
            <Label Class="fa fa-arrows handle" />
            <Spaces Size="5" />
            <Label Caption="@Data.SortOrder~" ID="sortorder" Class="sortorder" />
          </DataTableColumn>
        </DataTable>
        <IncludeScript IncludedScript="// List 2&#xD;&#xA;$('#items-2 tbody').sortable({&#xD;&#xA;&#xD;&#xA;    animation: 100,&#xD;&#xA;    handle: '.handle',&#xD;&#xA;    onEnd: function(evt) {&#xD;&#xA;        console.log('from: ' + evt.oldIndex + ' to ' + evt.newIndex);&#xD;&#xA;        var list = [];&#xD;&#xA;        $('.sortorder').each(function() {&#xD;&#xA;            list.push($(this).text());&#xD;&#xA;        });&#xD;&#xA;        $('#finalorder').val(list.toString());&#xD;&#xA;    }&#xD;&#xA;&#xD;&#xA;});&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;" />
      </Body>
      <ideTestParams />
    </Report>
    0

Please sign in to leave a comment.