Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

st-sort should treat null, undefined, and emtpy strings consistently. #669

Closed
tystol opened this issue May 3, 2016 · 9 comments
Closed

Comments

@tystol
Copy link

tystol commented May 3, 2016

When sorting rows based on model values via st-sort, currently empty strings are treated as smallest, undefined is treated as largest, and null is converted to the string "null" (ie. falls between "nukk" and "numm")

As all 3 are rendered into the DOM visually as an empty string, I feel the sort should be consistent and place all 3 at the start/end.

Latest version of smart table (2.1.8)
Recent version of angular (1.5.3)
http://plnkr.co/edit/BEBdzWI44z3BiIxRRDET?p=preview

@xpierro
Copy link

xpierro commented May 13, 2016

Have exactly the same problem, I would like empty object to be put at the top regardless of sorting :(

@virus17
Copy link

virus17 commented Jun 23, 2016

Is there any update here?

@afgonzal
Copy link

afgonzal commented Oct 1, 2016

Anyworkarounds at least?

@bbuie
Copy link

bbuie commented Oct 25, 2016

Nothing?

@ghost
Copy link

ghost commented Nov 14, 2016

I have similar (but not the same) problem. I need only rows where certain value is empty (null or undefined). Here is my code:

<table st-table="$ctrl.displayedCollection" st-safe-src="$ctrl.stories.all" class="table table-hover ">
  <thead>
  <tr>
    <th colspan="1">
      <input st-search="title" class="form-control" placeholder="Search by title" type="text">
    </th>
    <th colspan="1">
      <select st-search="assignee.name" st-input-event="change" class="form-control"
              placeholder="author">
        <option value="" selected>Select assignee</option>
        <option value="???">unassigned</option>
        <option ng-repeat="user in $ctrl.users.all">{{user.name}}</option>
      </select>
    </th>
    <th colspan="1">
      <select st-search="stage" st-input-event="change" class="form-control"
              placeholder="stage">
        <option value="" disabled selected>Select stage</option>
        <option ng-repeat="stage in $ctrl.stories.stages">{{stage}}</option>
      </select>
    </th>
    <th st-sort="created_at">Sort by age</th>
    <th st-sort="deadline_at">Sort by deadline</th>
    <th>
      <button class="btn btn-success" ui-sref="createStory">New story</button>
    </th>
  </tr>
  </thead>
  <tbody>
  <tr ng-repeat="row in $ctrl.displayedCollection">
    <td><a ui-sref="story({ _id: row._id })">{{::row.title}}</a></td>
    <td>{{::row.assignee.name}}</td>
    <td>{{::row.stage}}</td>
    <td am-time-ago="row.created_at"></td>
    <td am-time-ago="row.deadline_at"></td>
    <td><span class="glyphicon glyphicon-remove-sign story-grid--remove-btn"></span></td>
  </tr>
  </tbody>
</table>

Problem is with the field "assignee". If I set option value to "" it filters nothing. Expected behaviour is to filter out all but empty rows.

@tdharris
Copy link

I'd like to see null, undefined, and empty strings be treated consistently as well. In my case, I'd prefer to have them sorted at the bottom rather than the top.

@tanvi-inttra
Copy link

Is there any work around for this issue? as @tdharris suggested, seeing the empty strings at bottom would make more sense

@swatifursule
Copy link

In my case, I want empty object to be put at the top, to show as most recent entries..

whats the solution?

@lorenzofox3
Copy link
Owner

A solution to all of your issues would be to replace default angular orderBy filter by your own if you are not happy with its behavior. (cf #176)

In some cases it might just be a simple wrapper around the default one providing the third argument (comparator) which is not forwarded by smart-table

module.filter('customSort', ['orderBy',function customSort(orderBy){
  const customComp = () => {} //a custom comparator function you want to pass to orderBy
  return function customOrder ( array,predicate,direction){
      return orderBy(array,predicate,direction,customComp);
   }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants