locked
How to reset the sort order to 1 in jquery RRS feed

  • Question

  • User-1188570427 posted

    I have some code where I am re-sorting based on a rule that has changed.

    Some of the sort orders (if changing the order from 1 to 2).

    This changes the orders now to 2 and 3 (so it changes what was 1 to 2 and what was 2 to 3).

    I want it to reset back starting at 1. What is the best way to do this?

    function MoveOrder(items, ruleName, newSortOrder) {
        items.find(item => item.RuleName === ruleName).SortOrder = newSortOrder;
        items.forEach(item => {
            if (item.RuleName !== ruleName && item.SortOrder >= newSortOrder) {
                item.SortOrder = item.SortOrder + 1;
            }
        });
    }

    Thursday, October 31, 2019 9:57 PM

All replies

  • User288213138 posted

    Hi tvb2727,

    function MoveOrder(items, ruleName, newSortOrder) {
        items.find(item => item.RuleName === ruleName).SortOrder = newSortOrder;
        items.forEach(item => {
            if (item.RuleName !== ruleName && item.SortOrder >= newSortOrder) {
                item.SortOrder = item.SortOrder + 1;
            }
        });
    }

    A

    I have some code where I am re-sorting based on a rule that has changed.

    Some of the sort orders (if changing the order from 1 to 2).

    This changes the orders now to 2 and 3 (so it changes what was 1 to 2 and what was 2 to 3).

    I want it to reset back starting at 1. What is the best way to do this?

    function MoveOrder(items, ruleName, newSortOrder) {
        items.find(item => item.RuleName === ruleName).SortOrder = newSortOrder;
        items.forEach(item => {
            if (item.RuleName !== ruleName && item.SortOrder >= newSortOrder) {
                item.SortOrder = item.SortOrder + 1;
            }
        });
    }

    According to your code, I can't reproduce your question.

    Can you show me how did you define you items? What is the RuleName and SortOrder ?

    So please post your complete code.

    Best regardsm,

    Sam

    Friday, November 1, 2019 7:50 AM