使用javascript按升序和降序对分页的html内容进行排序

时间:2016-11-19 06:59:47

标签: javascript

对不起,如果在我新js之前询问这个问题,那么请帮助我。这是按升序和降序排序html内容的脚本,它运作得很好但我用这个分页然后在每个页面我必须选择升序和下降的顺序我想要它如果我将名称排序为升序,那么每个页面名称将按升序显示..

renderRow(rowData){
 const {uri} = rowData;
 return(
    <View style={{padding: 1, alignSelf: 'flex-start'}}>
       <Image style={styles.imageSize} source={{uri: uri}}>

         <View style={{position: 'absolute', backgroundColor: 'transparent'}}>
           <MyCheckBoxComponent/>
         </View>

       </Image>
   </View>
 )
}

1 个答案:

答案 0 :(得分:0)

我测试你的代码并修改它以使其正常工作(我们应该跳过th标题):

<script type="text/javascript">
var people, asc1 = 1,
    asc2 = 1,
    asc3 = 1;
window.onload = function () {
    people = document.getElementById("people");
}

function sort_table(tbody, col, asc) {
    var rows = tbody.rows,
        rlen = rows.length,
        arr = new Array(),
        i, j, cells, clen;
    // fill the array with values from the table
    for (i = 1; i < rlen; i++) { // *** i = 1 to skip th headers 
        cells = rows[i].cells;
        clen = cells.length;
        arr[i-1] = new Array(); // *** i-1
        for (j = 0; j < clen; j++) {
            arr[i-1][j] = cells[j].innerHTML; // *** i-1
        }
    }
    // sort the array by the specified column number (col) and order (asc)
    arr.sort(function (a, b) {
        return (a[col] == b[col]) ? 0 : ((a[col] > b[col]) ? asc : -1 * asc);
    });
    // replace existing rows with new rows created from the sorted array
    for (i = 1; i < rlen; i++) { // *** i = 1
        rows[i].innerHTML = "<td>" + arr[i-1].join("</td><td>") + "</td>"; //*** i-1
    }
}
</script>