2015-04-20 25 views
3

我有具有4列像下方的網格視圖:排序是不工作的IP地址列以ng柵

IP   | Name | Status |Value 

192.168.1.3 |MAS | UP  |x 

192.168.1.5 |HGR | UP  |Y 

192.168.1.10 |UYR |DOWN |Z 

192.168.1.7 |IOR |UP  |P 

我使用納克格框架來顯示這些。這裏的排序不適用於IP地址列,對其他列的工作正常。 我的專欄定義如下: -

columnDefs : [{ 
        field : 'ip', 
        displayName : 'IP', 
        width : '25%' 
       }, 
       { 
        field : 'name', 
        displayName : 'NAME', 
        width : '25%' 
       }, 
       { 
        field : 'status', 
        displayName : 'Status', 
        width : '25%' 
       }, 
       { 
        field : 'value', 
        displayName : 'Value', 
        width : '25%' 
       }]; 

對此有何想法?

+0

是它給予任何錯誤? – shakib

+0

不,它沒有給出任何錯誤..雖然數據顯示所有的列,但唯一的問題是排序不工作在IP地址列。 –

回答

2

默認情況下,該列應該執行字符串排序。在情況下,你的意思是,它應該做的數量排序,而串排序,你可以嘗試使用自定義排序功能的IP列,

columnDefs: [ 
    { 
    field: 'ip', 
    displayName: 'IP', 
    width: '25%', 
    sortFn: function (a, b) { 
     if (a == b) return 0; 
     if (+a.replace(/\./g, '') < +b.replace(/\./g, '')) return - 1; 
     return 1; 
    } 
    }, 
    { 
    field: 'name', 
    displayName: 'NAME', 
    width: '25%' 
    }, 
    { 
    field: 'status', 
    displayName: 'Status', 
    width: '25%' 
    }, 
    { 
    field: 'value', 
    displayName: 'Value', 
    width: '25%' 
    } 
]; 

希望這有助於

+0

仍然無效。我也使用你的代碼。它能夠在其他列上排序,但不能在ip上排序。這是一個CSS問題嗎?只是我猜測。 –

+0

你在'gridOptions'對象中使用了'sortInfo'嗎? – shakib

+0

我已經使用sortInfo是這樣的: - sortInfo:{fields:['ip'],directions:['asc']},但是當我刷新瀏覽器時,一旦按排序順序排序,但後來不排序。 –